Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Incidentally I'm using FilesMatch instead of AddHandler because it's more specific. –  Synchro Oct 18 '12 at 9:55
add comment

1 Answer 1

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.