8

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?

Rob
  • 344
  • 3
  • 15
Shane
  • 261
  • 2
  • 4
  • 8

4 Answers4

9

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.

Jakuje
  • 10,363
Mick
  • 203
2

It is possible that your fastcgi process is not authorized to read your /usr/lib/cgi-bin/ directory because the user that running the fastcgi process (you) doesn't belong to the same group that the owner of your /usr/lib/cgi-bin/ directory.

So, make sure of this :

$ stat /usr/lib/cgi-bin/

response :

bla bla... Uid: ( 33/www-data) Gid: ( 33/www-data)

Note : www-data is the user of Apache

If not, do this :

$ sudo chown -R www-data:www-data /usr/lib/cgi-bin

now check with the previous stat command if the user is www-data. Then, you have to add yourself (the user of the fastcgi process) to the user group www-data so :

$ sudo gpasswd -a ${USER} www-data

Now open /etc/php5/fpm/pool.d/www.conf with your favorite editor.

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

And uncomment those lines :

listen.owner = www-data
listen.group = www-data
listen.mode = 0660

Important : don't turn listen.mode into 666, it's not safe

sudo service apache2 restart
sudo service php5-fpm restart

And the show must go on :)

Azodium
  • 121
0

I had to ensure the Apache reference to FastCGI in /etc/apache2/conf-available/httpd.conf:

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

matched the listening PHP FastCGI process configured in /etc/php5/fpm/pool.d/www.conf:

listen = /var/run/apache2/php-fpm.sock

Once I had them matched I checked that FastCGI was actually running on the correct UNIX socket as described by @Mick (as usual prefix with sudo if not running as root):

lsof -U | grep php

which showed it was still incorrect:

php5-fpm  19438       root    7u  unix 0xffff880002242b40      0t0 79631 socket
php5-fpm  19438       root    8u  unix 0xffff880002242780      0t0 79632 socket
php5-fpm  19438       root    9u  unix 0xffff8800022423c0      0t0 79633 /var/run/php-fpm.sock
php5-fpm  19440   www-data    0u  unix 0xffff8800022423c0      0t0 79633 /var/run/php-fpm.sock
php5-fpm  19441   www-data    0u  unix 0xffff8800022423c0      0t0 79633 /var/run/php-fpm.sock
php5-fpm  19442   www-data    0u  unix 0xffff8800022423c0      0t0 79633 /var/run/php-fpm.sock
php5-fpm  19443   www-data    0u  unix 0xffff8800022423c0      0t0 79633 /var/run/php-fpm.sock

So a restart of the FastCGI process was required to pick up the config changes:

service php5-fpm restart
SharpC
  • 253
0

It sounds like you've started your web server without php5-fpm running and listening to a socket address. If you want to specify "/usr/lib/cgi-bin/php5-fcgi" as the listen address (a channel for fpm to process connections coming into it), you'll need to make sure that is in your fpm config. "/etc/php5/fpm/pool.d/www.conf" is a common path for it.

Then in your apache configuration, ensure .php files are using fastcgi_pass to send requests onto fpm. It sounds like it is already set up to do this, except it's expecting a unix socket in the wrong location.

Peter
  • 1,460