PHP5-FPM + Apache2 on Debian Wheezy : connect() failed with FastCGI

apache-2.2fastcgiphp-fpm

I have this error on Debian Wheezy, I don't understand what am I missing.
Logs from php5-fpm are OK.

Error from apache2 log:

[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"

The contents of fastcgi.conf:

<IfModule mod_fastcgi.c>
  AddHandler fastcgi-script .fcgi
  #FastCgiWrapper /usr/lib/apache2/suexec
  FastCgiIpcDir /var/lib/apache2/fastcgi
</IfModule>

The contents of 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>

The contents of 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

The Apache VHost www:

<VirtualHost *:80>
  ServerName xxxx.com

  ServerAdmin admin@xxxx.com
  DocumentRoot /home/web/xxxx/www/prod
  Options None

The Fast 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>

The output of grep www /etc/passwd:

www:x:1001:1001:,,,:/home/web/xxxx/www:/bin/bash

The output of 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

What am I missing?

Best Answer

in pool.d/www.conf, take note of

listen = /var/run/www.sock

in php5-fpm.conf, on this line:

FastCGIExternalServer /var/lib/apache2/fastcgi/php5.fastcgi -socket /var/run/php5-fpm.sock -idle-timeout 610

/var/run/php5-fpm.sock must be the same as the listen option in pool.d/www.conf

In VHost www :

FastCgiExternalServer /home/web/xxxx/www/cgi-bin/php5.external -idle-timeout 310 -flush -socket /var/run/www.sock

This line is useless without

Alias /php5.external /home/web/xxxx/www/cgi-bin/php5.external
Action php-script /php5.external virtual

Hope this help.