我在 ubuntu 18.04 上安装了 php8.1,但遇到了问题。我收到 502 Bad Gateway 错误。error.log 显示以下错误:
2022/06/30 17:48:38 [crit] 2224#2224: *1 connect() to unix:/var/run/php/php8.1-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: _, request: "GET /w3_scalar.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php8.1-fpm.sock:", host: "localhost
其他详情如下:
$ sudo nginx -t
[sudo] password for zulfi:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
和
$ sudo systemctl restart php8.1-fpm
~$ sudo systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en
Active: active (running) since Wed 2022-06-29 15:49:48 CDT; 1 day 2h ago
Docs: man:nginx(8)
Process: 2220 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code
Process: 2010 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process
Main PID: 2221 (nginx)
Tasks: 13 (limit: 4915)
CGroup: /system.slice/nginx.service
├─2221 nginx: master process /usr/sbin/nginx -g daemon on; master_pro
├─2224 nginx: worker process
├─2226 nginx: worker process
~$ journalctl -xe
-- Unit systemd-hostnamed.service has finished starting up.
--
-- The start-up result is RESULT.
Jun 30 17:58:08 lc2530hz audit[20050]: AVC apparmor="ALLOWED" operation="connect
Jun 30 17:58:08 lc2530hz audit[20050]: AVC apparmor="ALLOWED" operation="file_pe
Jun 30 17:58:08 lc2530hz audit[20050]: AVC apparmor="ALLOWED" operation="file_pe
Jun 30 17:58:08 lc2530hz audit[20050]: AVC apparmor="ALLOWED" operation="file_pe
Jun 30 17:58:08 lc2530hz audit[20050]: AVC apparmor="ALLOWED" operation="file_pe
Jun 30 17:58:08 lc2530hz kernel: audit: type=1400 audit(1656629888.891:266): app
Jun 30 17:58:08 lc2530hz kernel: audit: type=1400 audit(1656629888.891:267): app
Jun 30 17:58:08 lc2530hz kernel: audit: type=1400 audit(1656629888.891:268): app
Jun 30 17:58:08 lc2530hz kernel: audit: type=1400 audit(1656629888.891:269): app
Jun 30 17:58:08 lc2530hz kernel: audit: type=1400 audit(1656629888.891:270): app
Jun 30 17:58:09 lc2530hz org.gnome.Nautilus[4167]: func=xmlSecCheckVersionExt:fi
Jun 30 17:58:09 lc2530hz kernel: CPU4: Core temperature above threshold, cpu clo
Jun 30 17:58:09 lc2530hz kernel: CPU10: Core temperature above threshold, cpu cl
Jun 30 17:58:09 lc2530hz kernel: CPU4: Core temperature/speed normal
Jun 30 17:58:09 lc2530hz kernel: CPU10: Core temperature/speed normal
文件信息为:
/etc/php/8.1/fpm/php-fpm.conf
pid = /run/php/php8.1-fpm.pid
error_log = /var/log/php8.1-fpm.log
include=/etc/php/8.1/fpm/pool.d/*.conf
/etc/php/8.1/fpm/pool.d/www.conf:
user = www-data
group = www-data
listen = /run/php/php8.1-fpm.sock
listen.group = www-data
listen = 127.0.0.1:9000
请有人指导我如何解决当我使用 http://localhost/w3_scalar.php 在浏览器上执行 php 文件时出现的这个严重的 Gateway 502 错误
请注意,上述文件在 php 7.4 Zulfi 上运行。
==2022 年 7 月 3 日@Tom Yan :第一个命令
$ systemctl status php8.1-fpm
● php8.1-fpm.service - The PHP 8.1 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php8.1-fpm.service; enabled; vendor prese
Active: active (running) since Sun 2022-07-03 16:58:24 CDT; 42min ago
Docs: man:php-fpm8.1(8)
Process: 2087 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/ph
Main PID: 1921 (php-fpm8.1)
Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/se
Tasks: 3 (limit: 4915)
CGroup: /system.slice/php8.1-fpm.service
├─1921 php-fpm: master process (/etc/php/8.1/fpm/php-fpm.conf)
├─2079 php-fpm: pool www
└─2085 php-fpm: pool www
Jul 03 16:58:24 lc2530hz systemd[1]: Starting The PHP 8.1 FastCGI Process Manage
Jul 03 16:58:24 lc2530hz systemd[1]: Started The PHP 8.1 FastCGI Process Manager
第二条命令:
$ journalctl -bu php8.1-fpm
Failed to parse boot descriptor 'u'
但它与 php8.1-fpm 无关,请有人指导我。
$ sudo ps aux | grep 'php'
[sudo] password for zulfi:
root 1921 0.0 0.1 454156 27524 ? Ss 16:58 0:00 php-fpm: master process (/etc/php/8.1/fpm/php-fpm.conf)
www-data 2079 0.0 0.0 456452 13896 ? S 16:58 0:00 php-fpm: pool www
www-data 2085 0.0 0.0 456452 13896 ? S 16:58 0:00 php-fpm: pool www
zulfi 13627 0.0 0.0 210984 6284 ? Sl 17:39 0:00 /usr/lib/libreoffice/program/oosplash --writer file:///home/zulfi/Linux_Forum_SC%20Tools/nginx/nginx%20for%20php8/502%20bad%20gateway%20connect%20problem8p1.odt
zulfi 13646 99.7 2.7 2006652 443460 ? Rl 17:39 25:54 /usr/lib/libreoffice/program/soffice.bin --writer file:///home/zulfi/Linux_Forum_SC%20Tools/nginx/nginx%20for%20php8/502%20bad%20gateway%20connect%20problem8p1.odt --splash-pipe=5
zulfi 15893 0.0 0.0 14432 1116 pts/0 S+ 18:05 0:00 grep --color=auto php
另外:〜$ sudo systemctl is-active php8.1-fpm.service
活跃
@Tom Yan
$ ls -l /var/
total 52
drwxr-xr-x 2 root root 4096 Jul 3 17:03 backups
drwxr-xr-x 18 root root 4096 May 27 17:18 cache
drwxrwsrwt 2 root whoopsie 4096 Jun 22 16:44 crash
drwxr-xr-x 86 root root 4096 Feb 18 23:31 lib
drwxrwsr-x 2 root staff 4096 Apr 24 2018 local
lrwxrwxrwx 1 root root 9 Feb 8 2019 lock -> /run/lock
drwxrwxr-x 18 root syslog 4096 Jul 3 17:03 log
drwxrwsr-x 2 root mail 4096 Jul 24 2018 mail
drwxrwsrwt 2 root whoopsie 4096 Jul 24 2018 metrics
drwxr-xr-x 2 root root 4096 Jul 24 2018 opt
lrwxrwxrwx 1 root root 4 Feb 8 2019 run -> /run
drwxr-xr-x 21 root root 4096 Apr 12 23:08 snap
drwxr-xr-x 7 root root 4096 Jul 24 2018 spool
drwxrwxrwt 9 root root 4096 Jul 3 18:09 tmp
drwxrwxrwx 3 root root 4096 May 23 2019 w
@Tom Yan
仍然得到:2022/07/03 18:48:19 [crit] 2108#2108: *6 connect() to unix:/var/run/php/php8.1-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: _, request: "GET /w3_static.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php8.1-fpm.sock:", host: "localhost"
地位:
$ sudo systemctl status /var/run/php/php8.1-fpm.sock
[sudo] password for zulfi:
Unit var-run-php-php8.1\x2dfpm.sock.mount could not be found.
我的 listen=listen = /run/php/php8.1-fpm.sock,我应该将其更改为 /var/run/php8.1-fpm.sock 吗?
@Tom Yan,stat 给出了错误:
$stat /var/run/php/php8.1-fpm.sock
stat: cannot stat '/var/run/php/php8.1-fpm.sock': No such file or directory
我还有其他版本:
$ ls /etc/php
7.2 8.0 8.1
他们制造麻烦了吗?@Tom Yan ==2022 年 7 月 4 日
~$ ls /var/run/
acpid.pid initctl snap.docker
acpid.socket initramfs snapd-snap.socket
alsa libvirt snapd.socket
apache2 libvirtd.pid spice-vdagentd
avahi-daemon lock sshd
boltd log sshd.pid
console-setup lvm sudo
containerd lvmetad.pid systemd
crond.pid mlocate.daily.lock teamviewerd.ipc
crond.reboot mount teamviewerd.pid
cups mysqld thermald
dbus netns tmpfiles.d
dhclient6-wlp2s0.pid network udev
dhclient-wlp2s0.pid NetworkManager udisks2
dmeventd-client nginx.pid unattended-upgrades.lock
dmeventd-server php user
docker plymouth utmp
docker.pid pppconfig uuidd
docker.sock rsyslogd.pid wpa_supplicant
ebtables.lock sendsigs.omit.d xtables.lock
gdm3 shm
gdm3.pid snapd
和
@lc2530hz:
~$ ls /var/run/php
php8.1-fpm.pid
@lc2530hz:~$ 另外 www.conf 还有以下内容:
listen.user = www-data
并将 listen = 127.0.0.1:9000 更改为:
listen = 127.0.0.1
我还需要:
listen.owner = www-data
@Tom Yan,我收到了失败消息:
$ sudo systemctl restart php8.1-fpm
Job for php8.1-fpm.service failed because the control process exited with error code.
See "systemctl status php8.1-fpm.service" and "journalctl -xe" for details.
zulfi@lc2530hz:/etc/php/8.1/fpm/pool.d$ systemctl status php8.1-fpm.service
● php8.1-fpm.service - The PHP 8.1 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php8.1-fpm.service; enabled; vendor prese
Active: failed (Result: exit-code) since Mon 2022-07-04 18:26:53 CDT; 1min 54
Docs: man:php-fpm8.1(8)
和 $ journalctl -xe Jul 04 18:28:48 lc2530hz kernel: CPU6: 软件包温度高于阈值,cpu Jul 04 18:28:48 lc2530hz kernel: CPU1: 软件包温度高于阈值,cpu Jul 04 18:28:48 lc2530hz kernel: CPU7: 软件包
ag ==5-26-2023 @QuintenWu 我在这里检查了我的配置文件:
/etc/nginx$ ls
conf.d koi-win nginx.conf sites-enabled
fastcgi.conf mime.types proxy_params snippets
fastcgi_params modules-available scgi_params uwsgi_params
koi-utf modules-enabled sites-available win-utf
以下是我的 nginx 配置文件的内容:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
我找不到这一行:
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
请告诉我您要求我编辑哪个文件?
祖尔菲。
答案1
您是否更新了相应的 Web 服务器配置?例如来自
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
到
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
这对我来说很有帮助。
附言:抱歉,我刚刚才发现这个问题。晚了一年,但还是给你。