大网数据广告活动
服务器运维问答

PHP-FPM Failed to connect to FastCGI server

· 52CE 我爱测

Error log: [Sat Nov 22 05:24:41 2014] [error] [client xx] (2)No such file or directory: FastCGI: failed to connect to server "/usr/lib/cgi-bin/php5-fcgi": connect() failed [Sat Nov 22 05:24:41 2014] [error] [client xx] FastCGI: i…

问题原文

原帖链接 · Shane · CC BY-SA 3.0

Error log:

[Sat Nov 22 05:24:41 2014] [error] [client xx] (2)No such file or directory: FastCGI: failed to connect to server "/usr/lib/cgi-bin/php5-fcgi": connect() failed 
[Sat Nov 22 05:24:41 2014] [error] [client xx] FastCGI: incomplete headers (0 bytes) received from server "/usr/lib/cgi-bin/php5-fcgi"

Well, this file /usr/lib/cgi-bin/php5-fcgi indeed is missing, and there's actually nothing in cgi-bin folder. And when I restarts apache2 it seems to work all right:

[Sat Nov 22 04:46:29 2014] [notice] FastCGI: process manager initialized (pid 10747)
[Sat Nov 22 04:46:29 2014] [notice] Apache/2.2.22 (Ubuntu) mod_fastcgi/mod_fastcgi-SNAP-0910052141 mod_ssl/2.2.22 OpenSSL/1.0.1 configured -- resuming normal operations

/etc/apache2/conf.d/php-fpm.conf

<IfModule mod_fastcgi.c>
    AddHandler php5-fcgi .php
    Action php5-fcgi /php5-fcgi
    Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
    FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization
 </IfModule>

So what do I do now?

社区高分解答

原帖链接 · Mick · CC BY-SA 3.0

In short

I would bet that you are not using Unix Sockets in your php-fpm configuration. This is because by default php-fpm is using TCP ports.

Closer look at your configuration

You've decided to use Unix Sockets:

FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization

Therefore, you need to make sure php-fpm is actually running on those unix sockets.

Case 1: You are really using Unix Sockets

$ sudo lsof -U | grep php
// will show you
php-fpm   17330          root    5u  unix 0xf4f64800      0t0 7045381 socket
php-fpm   17330          root    7u  unix 0xf545f080      0t0 7045382 socket
php-fpm   17330          root    8u  unix 0xf55f3a80      0t0 7045383 /var/run/php5-fpm.sock
php-fpm   17331        nobody    0u  unix 0xf55f3a80      0t0 7045383 /var/run/php5-fpm.sock
php-fpm   17331        nobody    0u  unix 0xf55f3a80      0t0 7045383 /var/run/php5-fpm.sock

$sudo lsof -i | grep php
// should show nothing

Case 2: You are not using Unix Sockets but TCP ports

$ sudo lsof -U | grep php
// will show you
php-fpm   17330          root    5u  unix 0xf4f64800      0t0 7045381 socket
php-fpm   17330          root    7u  unix 0xf545f080      0t0 7045382 socket

$sudo lsof -i | grep php
php-fpm   13387    root    7u  IPv4 202656      0t0  TCP localhost:cslistener (LISTEN)
php-fpm   13388  nobody    0u  IPv4 202656      0t0  TCP localhost:cslistener (LISTEN)
php-fpm   13389  nobody    0u  IPv4 202656      0t0  TCP localhost:cslistener (LISTEN)

It's very likely that you get this error message because you are indeed not using unix sockets with php-fpm. The reason is that, php-fpm is configured by default to use tcp ports.

Open php-fpm.conf, and change to unix sockets:

sudo nano /etc/php5/fpm/pool.d/www.conf

# We don't want to use TCP ports
#listen = 127.0.0.1:9000

# We want to use Unix Sockets
listen = /var/run/php5-fpm.sock

Now, you will run into permission issues, on the same file:

// modify user and group and use same user as apache (here 'nobody')
user = nobody
group = nobody

// Uncomment those lines and use same user as apache (here 'nobody')
listen.owner = nobody
listen.group = nobody
listen.mode = 0666

PHP-FPM configuration is now using Unix Sockets, and Apache will be able to connect to it.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-11-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。