4

I have two sites that I run from apache 2.2 vhosts with PHP-FPM 5.4 on Ubuntu 12.04. Until now I've been using a server-wide (stock) mod_fastcgi config, but now I want to split this into two FPM pools so that I can use different PHP settings for each (e.g. one is a dev site so has error display enabled).

I've set up two FPM pools with different names and socket locations, as per the docs, disabled the global fastcgi config, copied it into my vhosts and altered it to point at the different pools for each vhost, like this:

<IfModule mod_fastcgi.c>
    <FilesMatch \.php$>
        SetHandler php-script
    </FilesMatch>
    Action php-script /php5.fcgi virtual
    Alias /php5.fcgi /var/fastcgi/php5.fcgi
    FastCGIExternalServer /var/fastcgi/php5.fcgi -socket /var/run/php5-fpm-www.sock
    <Directory "/var/fastcgi">
        Order allow,deny
        <Files "php5.fcgi">
            Order deny,allow
            Deny from all
            Allow from env=REDIRECT_STATUS
        </Files>
    </Directory>
</IfModule>

There are actually 4 vhosts as there are regular and SSL flavours of each hostname, and each pair points at one FPM pool.

The problem I run into is that apache throws an error saying:

FastCgiExternalServer: redefinition of previously defined class "/var/fastcgi/php5.fcgi"

How should this be done?

Synchro
  • 2,983
  • 5
  • 25
  • 35

1 Answers1

10

The trick is that you need to rename the action and alias too so they are not 'redefinitions', so for my 'www' pool, my vhost config looks like this:

<IfModule mod_fastcgi.c>
    <FilesMatch \.php$>
        SetHandler php-script
    </FilesMatch>
    Action php-script /php5-www.fcgi virtual
    Alias /php5-www.fcgi /var/fastcgi/php5-www.fcgi
    FastCGIExternalServer /var/fastcgi/php5-www.fcgi -socket /var/run/php5-fpm-www.sock
    <Directory "/var/fastcgi">
        Order allow,deny
        <Files "php5-www.fcgi">
            Order deny,allow
            Deny from all
            Allow from env=REDIRECT_STATUS
        </Files>
    </Directory>
</IfModule>

And for SSL on the same pool:

<IfModule mod_fastcgi.c>
    <FilesMatch \.php$>
        SetHandler php-script
    </FilesMatch>
    Action php-script /php5-www-ssl.fcgi virtual
    Alias /php5-www-ssl.fcgi /var/fastcgi/php5-www-ssl.fcgi
    FastCGIExternalServer /var/fastcgi/php5-www-ssl.fcgi -socket /var/run/php5-fpm-www.sock
    <Directory "/var/fastcgi">
        Order allow,deny
        <Files "php5-www-ssl.fcgi">
            Order deny,allow
            Deny from all
            Allow from env=REDIRECT_STATUS
        </Files>
    </Directory>
</IfModule>

So they're using different names, but pointing at the same socket.

Synchro
  • 2,983
  • 5
  • 25
  • 35