步骤
- 一、上传PHP项目到目录下
- 二、修改NGINX的配置:nginx.conf:
server
{
listen 80;
server_name XXX; #要修改的地方1
location /
{
root /www/wwwroot/XXXXX; # 要修改的地方2,项目的目录
index index.php index.html ;
}
location ~ .*\.php(\/.*)*$
{
root /www/wwwroot/XXXXX; # 要修改的地方3,项目的目录
fastcgi_pass 127.0.0.1:9000;
# fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
另一种配置:
server
{
listen 80;
server_name XXXXXXXXXXX;
root /www/wwwroot/XXX;
index index.html index.htm index.php;
location /
{
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ .*\.php(\/.*)*$
{
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
include fastcgi.conf;
}
}
- 三、修改php-fpm.conf:
listen = 127.0.0.1:9000
Tips:
其中 nginx中的fastcgi_pass 与php-fpm.conf中listen = /tmp/php-cgi.sock保持一致。
若php-fpm.conf中配置为listen = 127.0.0.1:9000
那么nginx中fastcgi_pass 为fastcgi_pass 127.0.0.0.1:9000
nginx 中 fastcgi_pass配置为unix:/tmp/php-fpm.sock与127.0.0.1:9000区别
- 四、
systemctl start php-fpm --启动php-fpm服务
有可能要php-fpm-74才行,根据提示打上版本号即可
其他有用的命令:
systemctl is-enabled php-fpm.service --查看是否开机启动
systemctl enable php-fpm.service --设置开机自动动
systemctl stop php-fpm -- 停止服务
systemctl reload php-fpm --重新加载
systemctl restart php-fpm --重启
sudo netstat -tupln| grep 9000 --查看端口号9000
- 五、
service nginx restart 重启NGINX服务
可能出现的错误:
1. Nginx服务器点击前台链接或者后台登录时出现404, not found
解决方式: nginx.conf里的location设置
location ~ .*\.php(\/.*)*$