1

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 [email protected]
  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?

2 Answers 2

1

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.

0

You can read about this here: http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html#FastCgiExternalServer

I'm assuming that you want to run each vhost as a different user/group. Otherwise you need only of them practically anywhere in your conf files (Could be in fastcgi.conf). For that, check out this url:

http://www.versatilewebsolutions.com/blog/2012/11/installing-apache-2-with-php-fastcgi-on-ubuntu-12-10.html

For the run as user thing, I'll try to explain how this works:

I don't think you have to touch php-fpm.conf, just leave it be like it is when you installed php5-fpm Without comments mine looks like this:

php-fpm.conf

[global]

pid = /var/run/php5-fpm.pid
error_log = /var/log/php5-fpm.log
include=/etc/php5/fpm/pool.d/*.conf

You seem to have one virtual host, so I don't know what you would do with 2 fastcgiexternalservers anyway.

The steps the php is squeezed through are the following:

  1. AddHandler php-script .php
  2. Action php-script /php5.fastcgi
  3. Alias /php5.fastcgi /var/lib/apache2/fastcgi/php5.fastcgi
  4. FastCgiExternalServer /var/lib/apache2/fastcgi/php5.fastcgi -socket php5-fpm.sock

Here at #4, the alias given at #3 will be resolved by the fastcgiexternalserver (the path does not have to exist), and the socket parameter is a filename relative to the FastCgiIpcDir you defined earlier. I'm using currently the following directory for that:

FastCgiIpcDir  /var/run/

Which will mean that your journey continues at /etc/php5/fpm/pool.d/www.conf

The important row is:

listen = /var/run/php5-fpm.sock

The path has to be the same as fastcgiipcdir plus the relative socketname, so the flow will be picked up here. Without comments:

www.conf

[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 = /

For each socket (for each site if each socket is different) you want to listen to, you have to create new conf files (like www.conf). The four steps I described earlier should be in each virtual host that you want to run as other user/group. I believe it should look like this:

Vhost 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>

After this, always make sure to give write access where the sockets will be created. That would be the fastcgiipcdir /var/run for me on ubuntu, which points to /run, so I just chmodded that:

chmod 777 /run

(Of course that's not very nice to do, but for demonstration and local testing it's fine)

Enable your site:

a2ensite site  //site: just whatever your www vhost conf file name is

And when you want to try it out, always restart both php-fpm and apache :

service php5-fpm restart
service apache2 restart

Try to understand these first, then making it work will be a piece of cake. I had my share of trying lots of different combinations but when I understood it, it made sense.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .