Ubuntu20.4 安装Nginx+PHP7.4+MySQL8
安装Nginx
1、首先添加nginx_signing.key(必须,否则出错)
$ wget http://nginx.org/keys/nginx_signing.key
$ sudo apt-key add nginx_signing.key
2、添加]Nginx](http://nginx.org/)官方提供的源
$ echo "deb http://nginx.org/packages/ubuntu/ trusty nginx" >> /etc/apt/sources.list
$ echo "deb-src http://nginx.org/packages/ubuntu/ trusty nginx" >> /etc/apt/sources.list
3、更新源并安装Nginx
$ sudo apt-get update
$ sudo apt-get install nginx
4、安装Nginx完成后可查看版本号,输入
$ /usr/sbin/nginx -v
安装PHP7.4
1、添加PPA
$ sudo apt-get install python-software-properties software-properties-common
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
2、安装PHP7以及所需的一些扩展
$ sudo apt install php7.4 php7.4-common php7.4-cli
$ sudo apt install php7.4-curl php7.4-json php7.4-gd php7.4-mbstring php7.4-intl php7.4-bcmath php7.4-bz2 php7.3-readline php7.3-zip
3、配置PHP7
打开php.ini配置文件:
$sudo vim /etc/php/7.4/fpm/php.ini
找到cgi.fix_pathinfo选项,去掉注释;,然后将值设置为0:
cgi.fix_pathinfo = 0;
display_errors = On
安装MySQL
安装mysql
$ sudo apt-get install mysql-server mysql-client
途中会提示设置MySQL的密码,安装好后:
$ mysql -uroot -p
然后输入刚刚设置的密码,能成功进入即成功安装。
nginx 与 php配置
nginx 配置文件/etc/nginx/nignx.conf
server {
listen 80;
server_name www.51zpt.com;
access_log /usr/local/nginx/logs/access-51zpt.log main;
error_log /usr/local/nginx/logs/error-51zpt.log;
location / {
root /home/www/51zpt;
try_files $uri $uri/ @router;
index index.html index.php index.htm;
}
location /nginx_status {
stub_status on;
access_log off;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location @router {
rewrite ^.*$ /index.php last;
}
location ~ \.php$ {
root /home/www/vote;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; //这一行和下面一行要加上,不然访问php文件可能出现空白!
fastcgi_param PATH_INFO $fastcgi_script_name;
include fastcgi_params;
}
location ~ ^/(status|ping)$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}
}
/etc/init.d/nginx -s reload
systemctl status nginx.service
/etc/init.d/php7.4-fpm reload
nginx和php链接的2种方式
一种是 sock 文件 一种是通过 9000 的fpm端口
ps -ef | grep php-fpm 查看php-fpm所有的进程
ps -ef | grep php-fpn.conf 查看配置所在路径
netstat -lntp 查看监听端口 listen/network/tcp/port