我在 Debian Wheezy 上遇到了这个错误,我不明白我错过了什么。php5-fpm 的日志没有问题。
错误来自阿帕奇2日志:
[error] (2)No such file or directory: FastCGI: failed to connect to server "/var/lib/apache2/fastcgi/php5.fastcgi": connect() failed
[error] FastCGI: incomplete headers (0 bytes) received from server "/var/lib/apache2/fastcgi/php5.fastcgi"
的内容fastcgi配置文件:
<IfModule mod_fastcgi.c>
AddHandler fastcgi-script .fcgi
#FastCgiWrapper /usr/lib/apache2/suexec
FastCgiIpcDir /var/lib/apache2/fastcgi
</IfModule>
的内容php5-fpm.conf:
<IfModule mod_fastcgi.c>
Alias /php5.fastcgi /var/lib/apache2/fastcgi/php5.fastcgi
AddHandler php-script .php
FastCGIExternalServer /var/lib/apache2/fastcgi/php5.fastcgi -socket /var/run/php5-fpm.sock -idle-timeout 610
Action php-script /php5.fastcgi virtual
# Forbid access to the fastcgi handler.
<Directory /var/lib/apache2/fastcgi>
<Files php5.fastcgi>
Order deny,allow
Allow from all
</Files>
</Directory>
# FPM status page.
<Location /php-fpm-status>
SetHandler php-script
Order deny,allow
Deny from all
Allow from 127.0.0.1 ::1
</Location>
# FPM ping page.
<Location /php-fpm-ping>
SetHandler php-script
Order deny,allow
Deny from all
Allow from 127.0.0.1 ::1
</Location>
</IfModule>
的内容pool.d/www.conf:
[www]
listen = /var/run/www.sock
; Permission socket
listen.owner = www
listen.group = www
; Utilsateur/Groupe des processus
user = www
group = www
; gestion des processus
pm = dynamic
pm = dynamic
pm.max_children = 500
pm.start_servers = 500
pm.min_spare_servers = 150
pm.max_spare_servers = 500
request_terminate_timeout = 605
; Status
pm.status_path = /php-fpm-status
ping.path = /php-fpm-ping
; log
access.log = /var/log/php/access.www.log
access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"
;Conf PHP
php_admin_value[open_basedir]=/home/web/xxx/www/prod
php_admin_value[session.save_path]=/home/web/xxx/www/tmp
php_admin_value[upload_tmp_dir]=/home/web/xxx/www/tmp
php_admin_value[error_log] = /var/log/php/error.www.log
php_admin_flag[log_errors] = on
php_admin_value[max_execution_time] = 0
php_admin_value[max_input_time] = 0
; upload
php_admin_value[upload_max_filesize] = 105M
php_admin_value[post_max_size] = 105M
阿帕奇虚拟主机 www:
<VirtualHost *:80>
ServerName xxxx.com
ServerAdmin [email protected]
DocumentRoot /home/web/xxxx/www/prod
Options None
这快速 CGI + FPM:
FastCgiExternalServer /home/web/xxxx/www/cgi-bin/php5.external -idle-timeout 310 -flush -socket /var/run/www.sock
Alias /cgi-bin/ /home/web/xxxx/www/cgi-bin/
<Directory /home/web/xxxx/www/prod/>
Options Indexes FollowSymLinks Includes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.www_prod.log
LogLevel debug
CustomLog /var/log/apache2/access.www_prod combined
</VirtualHost>
输出grep www /etc/passwd:
www:x:1001:1001:,,,:/home/web/xxxx/www:/bin/bash
输出apache2ctl -t -D DUMP_MODULES:
Loaded Modules:
core_module (static)
log_config_module (static)
logio_module (static)
version_module (static)
mpm_worker_module (static)
http_module (static)
so_module (static)
actions_module (shared)
alias_module (shared)
auth_basic_module (shared)
authn_file_module (shared)
authz_default_module (shared)
authz_groupfile_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
cgid_module (shared)
deflate_module (shared)
dir_module (shared)
env_module (shared)
fastcgi_module (shared)
mime_module (shared)
negotiation_module (shared)
reqtimeout_module (shared)
rewrite_module (shared)
setenvif_module (shared)
ssl_module (shared)
status_module (shared)
Syntax OK
我错过了什么?
答案1
在pool.d/www.conf中,注意
listen = /var/run/www.sock
在 php5-fpm.conf 中,在此行:
FastCGIExternalServer /var/lib/apache2/fastcgi/php5.fastcgi -socket /var/run/php5-fpm.sock -idle-timeout 610
/var/run/php5-fpm.sock 必须与pool.d/www.conf中的listen选项相同
在 VHost www 中:
FastCgiExternalServer /home/web/xxxx/www/cgi-bin/php5.external -idle-timeout 310 -flush -socket /var/run/www.sock
这条线没有用
Alias /php5.external /home/web/xxxx/www/cgi-bin/php5.external
Action php-script /php5.external virtual
希望这有帮助。
答案2
您可以在这里阅读相关内容:http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html#FastCgiExternalServer
我假设您想以不同的用户/组运行每个 vhost。否则,您实际上只需要在 conf 文件中的任何地方(可能是在 fastcgi.conf 中)使用它们。为此,请查看此 URL:
对于以用户身份运行的事情,我将尝试解释其工作原理:
我认为您不必触碰 php-fpm.conf,只需保持它与您安装 php5-fpm 时一样即可。没有注释,我的样子如下:
php-fpm.conf
[global]
pid = /var/run/php5-fpm.pid
error_log = /var/log/php5-fpm.log
include=/etc/php5/fpm/pool.d/*.conf
您似乎有一个虚拟主机,所以我不知道您会用 2 个 fastcgiexternalservers 做什么。
php 压缩经过的步骤如下:
- 添加处理程序 php 脚本 .php
- 操作 php-script /php5.fastcgi
- 别名 /php5.fastcgi /var/lib/apache2/fastcgi/php5.fastcgi
- FastCgiExternalServer /var/lib/apache2/fastcgi/php5.fastcgi -socket php5-fpm.sock
在这里 #4,#3 给出的别名将由 fastcgiexternalserver 解析(路径不必存在),并且套接字参数是相对于您之前定义的 FastCgiIpcDir 的文件名。我目前使用以下目录:
FastCgiIpcDir /var/run/
这意味着你的旅程将继续在 /etc/php5/fpm/pool.d/www.conf
重要的一行是:
listen = /var/run/php5-fpm.sock
该路径必须与 fastcgiipcdir 加上相对套接字名称相同,因此流程将在此处被拾取。无注释:
閣下網站
[www]
user = www-data
group = www-data
listen = /var/run/php5-fpm.sock
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chdir = /
对于您要监听的每个套接字(如果每个套接字不同,则针对每个站点),您必须创建新的 conf 文件(如 www.conf)。我之前描述的四个步骤应该在每个您要以其他用户/组身份运行的虚拟主机中。我相信它应该看起来像这样:
虚拟主机 www
<VirtualHost *:80>
ServerName xxxx.com
ServerAdmin [email protected]
DocumentRoot /home/web/xxxx/www/prod
Options None
AddHandler php-script .php
Action php-script /php5.fastcgi
Alias /php5.fastcgi /var/lib/apache2/fastcgi/php5.fastcgi
FastCgiExternalServer /var/lib/apache2/fastcgi/php5.fastcgi -socket php5-fpm.sock
<Directory /home/web/xxxx/www/prod/>
Options Indexes FollowSymLinks Includes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.www_prod.log
LogLevel debug
CustomLog /var/log/apache2/access.www_prod combined
</VirtualHost>
在此之后,一定要确保授予写权限套接字将创建的位置。对我来说,在 ubuntu 上,该位置是 fastcgiipcdir /var/run,它指向 /run,因此我只需对其进行 chmod 即可:
chmod 777 /run
(当然这样做不太好,但对于演示和本地测试来说还是可以的)
启用你的站点:
a2ensite site //site: just whatever your www vhost conf file name is
当你想尝试一下的时候,始终重新启动 php-fpm 和 apache:
service php5-fpm restart
service apache2 restart
首先尝试理解这些,然后让它工作起来就会是小菜一碟。我尝试了很多不同的组合,但当我理解了它,它就变得有意义了。