Saturday, December 1, 2012

ISPConfig + NginX + PHP-FPM + multiple PHP versions

This article is about setting up multiple PHP versions with PHP-FPM with nginx. Basically, its a note for myself, but maybe you can also use it. When this article was written, the stable PHP version was 5.4.9, so I will use that here.

It's a testing configuration, there might be security bugs, so don't use it in production!

This article is based on Ondřej Šimek's article.

So first of all, we need the actual PHP stable version, download it, unzip it, and copy it to /usr/local/src. After PHP 5.4.0, you don't need to patch. (if you need previous version, use Ondřej Šimek's tutorial for patching)

tar xjf php-5.4.9.tar.gz

mkdir /usr/local/src/php
mkdir /usr/local/src/php/5.4.9
mv php-5.4.9 /usr/local/src/5.4.9

Next, we need to run ./configure, and compile it. I like to install php separately to /opt/php/5.4.9

mkdir /opt/php
mkdir /opt/php/5.4.9

So run ./configure with the choosen options. You need at least these:

./configure --prefix=/opt/php/5.4.9 --enable-fpm --without-pear

You may or may not need to use --enable-fastcgi, it depends on the php-version, as I can remember, since 5.3.0 you don't need to use, because it's a must-have option.

After running configure, run:

make & make install

It will create some files in /opt/php/5.4.9. You may need to copy the recommended php.ini from the source folder:

cp /usr/local/src/php-ini-production /opt/php/5.4.9

Now, you need to change some configurations in the inis:

nano /opt/php/5.4.9/etc/php-fpm

ISPConfig uses listen port 9000, so you need to change it, to for example: 9001. You may want to set up logging, you can find several lines and settings about logging, its not hard to find.

Now, you can start php-fpm:


Next, go to your admin panel (ISPConfig), go to System, and additional PHP versions (only available in ISPConfig 3.0.5!). Create a new php version:

FastCGI settings:
Binary: /opt/php/5.4.9/bin
PHP.ini directory: /opt/php/5.4.9

PHP-FPM settings:
init-script: /opt/php/5.4.9/etc
PHP.ini directory: /opt/php/5.4.9/
POOL directory: /opt/php/5.4.9

Save it, then go to websites, and change PHP-version where you need. It will throw a ,,Bad Gateway" error,  because you didn't edit the nginx settings:

cd /etc/nginx/sites-available
nano yoursite.vhost

Then change the listen port to the port you defined earlier.


At the and: reload nginx and hurray.

/etc/init.d/nginx reload


Now, I have to figure out how to automatise the port change in the .vhost files.. 

No comments:

Post a Comment