目录

linux

ubuntu

用户名:ubuntu

秘钥:

系统更新

sudo apt upgrade
sudo apt update

nginx

官方安装指南:

https://nginx.org/en/linux_packages.html

server {
        listen 80;
    
        server_name the7.xxx.com;
    
        root /data/the7/;
        index index.html index.php;
    
        location / {
                if (!-e $request_filename) {
                        rewrite  ^(.*)$  /index.php?s=/$1  last;
                        break;
                }
        }
        location ~ \.php$ { 
                fastcgi_index  index.php;                
                include        fastcgi_params;
                #fastcgi_pass   127.0.0.1:9000;
                fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|mp3)$ {
                expires      30d;
        }
    
        location ~ .*\.(js|css)?$ {
                expires      12h;
        }
}   

在访问php后缀路径出现502错误时(访问html文件正常),排查错误日志,一般是sock文件权限不足

可以子nginx.conf中把user nginx 改为user [php-fpm对应的user]

#fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_pass unix:/run/php/php-fpm.sock;

其中include的fastcgi_params配置文件如下:

这个文件一般在/etc/nginx/目录下

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

mysql

官方文档:

https://nginx.org/en/linux_packages.html

https://dev.mysql.com/doc/refman/8.0/en/linux-installation.html

参考:

wget https://repo.mysql.com//mysql-apt-config_0.8.16-1_all.deb

sudo dpkg -i /home/ubuntu/mysql-apt-config_0.8.16-1_all.deb

sudo apt update


php

sudo apt-cache show php-fpm
sudo apt install php-fpm

#ubuntu 20.04 默认的php-fpm 自带以下新包安装,含php7.4

....
The following NEW packages will be installed:
  php-common php-fpm php7.4-cli php7.4-common php7.4-fpm php7.4-json php7.4-opcache php7.4-readline
....


其他扩展

sudo apt install php7.4-curl php7.4-xml php7.4-gd php7.4-mbstring php7.4-zip php-redis

git

https://git-scm.com/download/linux

sudo apt install git