Setting up PHP-FPM on Rimuhosting Ubuntu 13.04 VPS
I set up a VPS on Rimuhosting using their default Ubuntu 13.04 image and then attempted to follow the instructions on Alex Cabal‘s PHP Best Practices for configuring PHP-FPM.
Basically, it went like this:
#uncomment six multiverse lines
vim /etc/apt/sources.list
apt-get update
apt-get install apache2-mpm-worker libapache2-mod-fastcgi php5-fpm
# enable PHP-FPM in Apache
vim /etc/apache2/conf.d/php-fpm
Then I entered the suggested code:
<VirtualHost *:80>
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -idle-timeout 120 -pass-header Authorization
</VirtualHost>
And finally, a restart of Apache and PHP-FPM:
service apache2 restart && service php5-fpm restart
I then created /var/www/test.php
containing <?php phpinfo(); ?>
and tried loading it in my browser. I got an internal server error. :-(
I noticed in my error log:
root@cng:/var/log/apache2# tail -2 error.log
[Fri Feb 21 09:34:07 2014] [error] [client *.*.*.*] (111)Connection refused: FastCGI: failed to connect to server "/usr/lib/cgi-bin/php5-fcgi": connect() failed, referer: http://*.*.*.*/
[Fri Feb 21 09:34:07 2014] [error] [client *.*.*.*] FastCGI: incomplete headers (0 bytes) received from server "/usr/lib/cgi-bin/php5-fcgi", referer: http://*.*.*.*/
A comment on Cabal’s more detailed instructions from “Joe” suggested: look inside /etc/php5/fpm/pool.d/www.conf
, which revealed FPM listens to /var/run/php5-fpm.sock
.
So I removed -host 127.0.0.1:9000
from the Apache configuration and added -socket /var/run/php5-fpm.sock
, leaving me with a final /etc/apache2/conf.d/php-fpm
:
<VirtualHost *:80>
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -idle-timeout 120 -pass-header Authorization
</VirtualHost>
After another Apache restart, my PHP file loaded just fine and indicated “Server API: FPM/FastCGI”!
I assume the original instructions were supposed to have PHP-FPM listening on Port 9000 instead of via the socket, but I didn’t explore the configuration further. Not enough time!