![FCGI:尝试使用 unix 套接字连接到 127.0.0.1:9000 (*) 失败 Apache 2.4、PHP7.1-FPM](https://linux22.com/image/1579828/FCGI%EF%BC%9A%E5%B0%9D%E8%AF%95%E4%BD%BF%E7%94%A8%20unix%20%E5%A5%97%E6%8E%A5%E5%AD%97%E8%BF%9E%E6%8E%A5%E5%88%B0%20127.0.0.1%3A9000%20(*)%20%E5%A4%B1%E8%B4%A5%20Apache%202.4%E3%80%81PHP7.1-FPM.png)
我正在尝试在 MacOS Mojave 上设置 PHP7.1-FPM!我遵循了本指南并一直坚持到最后,直到它停止工作。
在 Google 搜索期间,我决定尝试使用 unix 套接字,因此我的某些配置与我尝试遵循的指南略有不同。
我已经安装了我的服务:
$ sudo brew services list
Name Status User Plist
httpd started root /Library/LaunchDaemons/homebrew.mxcl.httpd.plist
[email protected] started root /Library/LaunchDaemons/[email protected]
我已经设置了我的httpd.conf
:
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.php index.html index.htm
</IfModule>
<VirtualHost *:*>
ProxyPassMatch "^/(.*\.php(/.*)?)$" "fcgi://127.0.0.1:9000/usr/local/var/www/$1"
</VirtualHost>
<FilesMatch \.php$>
SetHandler "proxy:unix:/usr/var/run/php7.1-fpm.sock|fcgi://localhost/"
</FilesMatch>
在我的/etc/php-fpm.d/www.conf
我有
listen = /var/run/php/php7.1-fpm.sock
如果我检查这些进程,一切似乎都很好:
$ ps aux | grep php-fpm 10.2s Thu 17 Jan 14:15:40 2019
finnlesueur 3718 0.0 0.0 4268052 692 s001 S+ 12:28pm 0:00.01 tail -f /usr/local/var/log/php-fpm.log
finnlesueur 30588 0.0 0.0 4268060 812 s000 S+ 2:15pm 0:00.00 grep --color=auto php-fpm
_www 29371 0.0 0.0 4520960 1180 ?? S 2:08pm 0:00.00 /usr/local/opt/[email protected]/sbin/php-fpm --nodaemonize
_www 29370 0.0 0.0 4520960 1080 ?? S 2:08pm 0:00.00 /usr/local/opt/[email protected]/sbin/php-fpm --nodaemonize
root 29366 0.0 0.1 4518912 30808 ?? Ss 2:08pm 0:00.08 /usr/local/opt/[email protected]/sbin/php-fpm --nodaemonize
$ ps aux | grep httpd
finnlesueur 29346 0.0 0.0 4345112 1832 ?? S 2:08pm 0:00.00 /usr/local/opt/httpd/bin/httpd -D FOREGROUND
root 29332 0.0 0.0 4309296 2720 ?? Ss 2:08pm 0:00.09 /usr/local/opt/httpd/bin/httpd -D FOREGROUND
finnlesueur 30727 0.0 0.0 4268060 812 s000 S+ 2:16pm 0:00.00 grep --color=auto httpd
finnlesueur 29350 0.0 0.0 4328728 1172 ?? S 2:08pm 0:00.00 /usr/local/opt/httpd/bin/httpd -D FOREGROUND
finnlesueur 29349 0.0 0.0 4345112 1180 ?? S 2:08pm 0:00.00 /usr/local/opt/httpd/bin/httpd -D FOREGROUND
finnlesueur 29348 0.0 0.0 4353304 1184 ?? S 2:08pm 0:00.00 /usr/local/opt/httpd/bin/httpd -D FOREGROUND
finnlesueur 29347 0.0 0.0 4335896 1192 ?? S 2:08pm 0:00.00 /usr/local/opt/httpd/bin/httpd -D FOREGROUND
我DocumentRoot
有一个index.php
只是回显的地方phpinfo();
,这似乎也很好,但是当我加载本地主机时,我看到503 Service Unavailable
并在我的 HTTP 错误日志中得到:
[Thu Jan 17 14:18:57.654807 2019] [authz_core:debug] [pid 29347] mod_authz_core.c(817): [client ::1:57866] AH01626: authorization result of Require all granted: granted
[Thu Jan 17 14:18:57.654991 2019] [authz_core:debug] [pid 29347] mod_authz_core.c(817): [client ::1:57866] AH01626: authorization result of <RequireAny>: granted
[Thu Jan 17 14:18:57.655083 2019] [authz_core:debug] [pid 29347] mod_authz_core.c(845): [client ::1:57866] AH01628: authorization result: granted (no directives)
[Thu Jan 17 14:18:57.655119 2019] [proxy_fcgi:debug] [pid 29347] mod_proxy_fcgi.c(108): [client ::1:57866] AH01060: set r->filename to proxy:fcgi://127.0.0.1:9000/usr/local/var/www/index.php
[Thu Jan 17 14:18:57.655162 2019] [proxy:debug] [pid 29347] mod_proxy.c(1246): [client ::1:57866] AH01143: Running scheme fcgi handler (attempt 0)
[Thu Jan 17 14:18:57.655171 2019] [proxy_fcgi:debug] [pid 29347] mod_proxy_fcgi.c(1019): [client ::1:57866] AH01076: url: fcgi://127.0.0.1:9000/usr/local/var/www/index.php proxyname: (null) proxyport: 0
[Thu Jan 17 14:18:57.655183 2019] [proxy_fcgi:debug] [pid 29347] mod_proxy_fcgi.c(1028): [client ::1:57866] AH01078: serving URL fcgi://127.0.0.1:9000/usr/local/var/www/index.php
[Thu Jan 17 14:18:57.655191 2019] [proxy:debug] [pid 29347] proxy_util.c(2313): AH00942: FCGI: has acquired connection for (*)
[Thu Jan 17 14:18:57.655199 2019] [proxy:debug] [pid 29347] proxy_util.c(2367): [client ::1:57866] AH00944: connecting fcgi://127.0.0.1:9000/usr/local/var/www/index.php to 127.0.0.1:9000
[Thu Jan 17 14:18:57.655219 2019] [proxy:debug] [pid 29347] proxy_util.c(2576): [client ::1:57866] AH00947: connected /usr/local/var/www/index.php to 127.0.0.1:9000
[Thu Jan 17 14:18:57.655346 2019] [proxy:error] [pid 29347] (61)Connection refused: AH00957: FCGI: attempt to connect to 127.0.0.1:9000 (*) failed
[Thu Jan 17 14:18:57.655367 2019] [proxy_fcgi:error] [pid 29347] [client ::1:57866] AH01079: failed to make connection to backend: 127.0.0.1
[Thu Jan 17 14:18:57.655375 2019] [proxy:debug] [pid 29347] proxy_util.c(2328): AH00943: FCGI: has released connection for (*)
但是我的 PHP-FPM 日志中没有任何内容,我猜是因为尚未建立连接。
我已经在 Google 上搜索了好几个小时,但似乎找不到任何有用的信息。任何帮助都将不胜感激!
如果我可以提供更多信息,请告诉我!
更新 1
$ sudo lsof -U | grep php
php-fpm 29366 root 5u unix 0xf497a489280ca0c1 0t0 ->0xf497a489280c91e9
php-fpm 29366 root 6u unix 0xf497a489280c91e9 0t0 ->0xf497a489280ca0c1
php-fpm 29366 root 7u unix 0xf497a489280c9a81 0t0 /var/run/php/php7.1-fpm.sock
php-fpm 29370 _www 8u unix 0xf497a489280c9a81 0t0 /var/run/php/php7.1-fpm.sock
php-fpm 29371 _www 8u unix 0xf497a489280c9a81 0t0 /var/run/php/php7.1-fpm.sock
答案1
归根结底,这只是一个简单的错误。
我正在编辑一个www.conf
文件,结果/etc/php-fpm.d/www.conf
发现它是来自默认的 MacOS 安装。
我使用 Brew 安装的 PHP7.1-FPM文件www.conf
位于:
/usr/local/etc/php/7.1/php-fpm.d/www.conf
。
一旦我改变了listen
指令,/usr/local/etc/php/7.1/php-fpm.d/www.conf
我就可以开始比赛了。