Ubuntu – PHP-FPM with Apache 2.2.22 and Ubuntu 12.10 – 500 Error, or returns text (not executing)

apache-2.2PHPphp-fpmUbuntu

I am following this tutorial to try to install PHP-FPM on my LAMP stack.

My config in /etc/apache2/sites-available/default contains (as per the guide)

<IfModule mod_fastcgi.c>
        Alias /php5.fastcgi /var/www/fastcgi/php5.fastcgi
        AddHandler php-script .php
        FastCGIExternalServer /var/www/fastcgi/php5.fastcgi -socket /var/run/php-fpm.sock
        Action php-script /php5.fastcgi virtual

# This part is not necessary to get it to work, but it stops anything else from being
# accessed from it by mistake or maliciously.
        <Directory "/var/www/fastcgi">
                Order allow,deny
                <Files "php5.fastcgi">
                        Order deny,allow
                </Files>
        </Directory>
</IfModule>

Which resulted in 500 errors. I checked the Apache log and am seeing:

(111)Connection refused: FastCGI: failed to connect to server
"/usr/lib/cgi-bin/php5-fcgi": connect() failed FastCGIExternalServer
/var/www/fastcgi/php5.fastcgi -socket /var/run/php-fpm.sock
FastCGI: incomplete headers (0 bytes) received from server "/usr/lib/cgi-bin/php5-fcgi"

I checked and realised my /etc/php5/fpm/pool.d/www.conf was listening on a different socket location (from the tutorial), so I updated the apache config to:

FastCGIExternalServer /var/www/fastcgi/php5.fastcgi -socket /var/run/php5-fpm.sock

But now visiting a php5 script just shows plain text.

I'm not sure where I'm going wrong here, can anyone point me in the right direction to troubleshooting this? Unfortunately everything I've found is very NGINX oriented (or the user just switched to NGINX entirely!) I am somewhat tied to Apache at the moment as I am relying on .htaccess for wordpress and permalink rewrites etc.

Endless thanks in advance.

Best Answer

Try using the parameters -idle-timeout and -appConnTimeout in the FastCgiExternalServer in the httpd.conf. Check this out for the syntax