youland 发表于 2020-4-18 20:47

在树莓派上在线安装web服务

树莓派支持安装web服务,可以做网站。web服务器安装的软件分别为:nginx,php,mariadb

以下教程为在pi4 Raspbian 10.3上安装成功,安装前,请选择比较快的源,并且以root用户安装。同时,这个教程也适用其它的debian系统。在线安装的好处是,所有的软件总是处于最新状态。

1,切换到root用户

su root

输入两次root密码

2,更新源

apt-get update -y
apt-get upgrade -y
apt-get dist-upgrade -y

apt-get install -y rpi-update

3,安装php7.3

apt-get install -y php7.3 php7.3-common php7.3-cli php7.3-fpm php7.3-json php7.3-mysql php7.3-zip php7.3-gdphp7.3-mbstring php7.3-curl php7.3-xml php7.3-bcmath

4,安装nginx

apt-get install -y nginx

5,配置php.ini和nginx.conf

sed -i 's/^;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php/7.3/fpm/php.ini

sed -i 's/# server_names_hash_bucket_size/server_names_hash_bucket_size/' /etc/nginx/nginx.conf

6,配置nginx

cat > /etc/nginx/sites-enabled/default << "EOF"
# Default server
server {
      listen 80 default_server;
      listen [::]:80 default_server;
      
      server_name _;
      root /var/www/default;
      index index.php index.html index.htm default.html;

      location / {
                try_files $uri $uri/ =404;
      }

      # pass the PHP scripts to FastCGI server
      location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.3-fpm.sock;
      }

      # optimize static file serving
      location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
                access_log off;
                log_not_found off;
                expires 30d;
      }

      # deny access to .htaccess files, should an Apache document root conflict with nginx
      location ~ /\.ht {
                deny all;
      }
}
EOF

mkdir -p /var/www/default

wget -P /var/www/default https://gitee.com/nbweb/dnmp_d/raw/master/p.php

rm -rf /var/www/html
chown www-data:www-data -R /var/www
chmod g+s -R /var/www/.

systemctl restart php7.3-fpm
systemctl restart nginx

7,安装mariadb-server和mariadb-client

apt-get install -y mariadb-server mariadb-client

设置mariadb的密码

mysqladmin -u root password "123456"

systemctl restart mysql

8,安装phpmyadmin

wget -P /var/www/default https://files.phpmyadmin.net/phpMyAdmin/5.0.2/phpMyAdmin-5.0.2-all-languages.tar.gz
cd /var/www/default
tar zxf phpMyAdmin-5.0.2-all-languages.tar.gz
mv phpMyAdmin-5.0.2-all-languages phpmyadmin



页: [1]
查看完整版本: 在树莓派上在线安装web服务