最近更新了下ubuntu系统突然本地项目不能打开并且报502错误,因为本地项目为laravel所以在index.php打印phpinfo信息发现没有还是502,因为之前有踩过php-fpm的坑所以第一个联想到的php-fpm,因为更新前的php版本为php8.0所以查看了下发现php8.0-fpm不能启用了。后面查看一下php版本才发现被更新到php8.1。
root@Xing:/etc/systemd/system# systemctl status php8.0-fpm.service
○ php8.0-fpm.service
Loaded: masked (Reason: Unit php8.0-fpm.service is masked.)
Active: inactive (dead)
hyx@Xing:~$ systemctl status php8.1-fpm #查看fpm状态
● php8.1-fpm.service - The PHP 8.1 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php8.1-fpm.service; enabled; vendor pr>
Active: active (running) since Wed 2022-06-15 21:03:48 CST; 52min ago
Docs: man:php-fpm8.1(8)
Process: 17773 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /ru>
Main PID: 17770 (php-fpm8.1)
Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req>
Tasks: 3 (limit: 18983)
Memory: 9.8M
CPU: 285ms
CGroup: /system.slice/php8.1-fpm.service
├─17770 "php-fpm: master process (/etc/php/8.1/fpm/php-fpm.conf)" >
├─17771 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "">
└─17772 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "">
6月 15 21:03:48 Xing systemd[1]: Starting The PHP 8.1 FastCGI Process Manager...
6月 15 21:03:48 Xing systemd[1]: Started The PHP 8.1 FastCGI Process Manager.
知道了是php-fpm版本的不同导致的问题,那么nginx监听的fpm.sock就要改成php8.1的路径也就是fastcgi_pass 的配置
location ~* \.php$ {
fastcgi_index index.php;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
修改重启后发现还是502的问题。
第二个联想到新的fpm可能配置有问题,查看到fpm的配置如下,因为我的网站的用户为www而配置默认为www-data所以修改一下几个配置为www然后重启fpm之后访问成功。
user = www-data
group = www-data
listen.owner = www-data
listen.group = www-data
最好的解决路径:其实正常情况第一个联想的应该是nginx是否有问题。但我看nginx执行上是没问题的。所以直接想到fpm版本问题。正常情况下查看nginx.conf 查看错误日志位置,也就是error_log的配置。我的配置位置是 logs/error.log查看到以下报错
2293#0: *6 connect() to unix:/run/php/php8.1-fpm.sock failed (13:
Permission denied) while connecting to upstream, client:
127.0.0.1, server: test.com, request: “GET / HTTP/1.1”, upstream: “fastcgi://unix:/run/php/php8.1-fpm.sock:”, host:
“test.com”
host:“test.com”(是我的映射本地的网址)也就是访问了test.com这个连接
Permission denied 提示没有权限,原因是因为更新的php8.1的fpm是默认www-data这个组用户,而我的nginx的用户配置的是www这个用户。