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
#!/bin/sh
# Set desired PHP_FCGI_* environment variables.
# PHP FastCGI processes exit after 500 requests by default.
PHP_FCGI_MAX_REQUESTS=10000
export PHP_FCGI_MAX_REQUESTS

# 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/php5217.teurasporsaat.org
<VirtualHost *:80>
ServerName php5217.teurasporsaat.org
DocumentRoot /var/www/php5217.teurasporsaat.org
<Directory />
Options +ExecCGI
AddHandler fcgid-script .php
FCGIWrapper /usr/local/bin/php-5.2.17-wrapper
DirectoryIndex index.php index.html
</Directory>
</VirtualHost>

5. Restart apache. Open a beer. Hooray!

 

 

Leave a Reply