HOWTO configure multiple versions of PHP for different virtual hosts with apache2 and fcgid

Had a little project for setting up a host for development / hosting legacy stuff and found that the information about this is pretty scattered / shitty. So, here goes. Done on a recent Ubuntu but should be pretty straight-forward on any distro:

1. Install apache2, libxml2 and libapache2-mod-fcgid (apt-get install, yum install, pick your poison..)

2. Configure && compile your PHP. For the 5.2 branch you need to throw in a patch  (wget that to your php-5.2.17-dir and say patch -p0 < filename.patch) to compile against more modern libxml2. The options for enabling fastcgi support have changed with pretty much every release, but this does the trick: ./configure –enable-fastcgi –with-fastcgi –enable-cgi && make

3. Create wrappers for all your php versions. We’re being lazy here and run them directly from  /usr/src/ where we compiled it. No messy make installs. Pretty much like this:

cat /usr/local/bin/php-5.2.17-wrapper
# Set desired PHP_FCGI_* environment variables.
# PHP FastCGI processes exit after 500 requests by default.

# Replace with the path to your FastCGI-enabled PHP executable
exec /usr/src/php-5.2.17/sapi/cgi/php-cgi

4. Set up your virtual hosts:

cat /etc/apache2/sites-enabled/
<VirtualHost *:80>
DocumentRoot /var/www/
<Directory />
Options +ExecCGI
AddHandler fcgid-script .php
FCGIWrapper /usr/local/bin/php-5.2.17-wrapper
DirectoryIndex index.php index.html

5. Restart apache. Open a beer. Hooray!



Leave a Reply