This is a very strange topic: even though a cursory google search using the words “multiple php versions apache” spits out a considerable amount of informative howtos and blog entries, when I recently mentioned in a mailing list that it is in fact quite easy to have multiple php installs running in parallel using Apache virtual hosts, I immediately received a private request for my configuration.
Well, here it is, along with a few details on how to set up the complete environment.
The desired goal is having “alot” of php installations running in parallel, so that php scripts can be quickly tested against as many versions of php as possible. It is very useful f.e. when
- you are migrating an existing app from php 4 to version 5
- you are deploying your applications on a large base of servers where different versions of php are installed, but develop all the different apps on the same workstation
- you develop a popular open source php library or shrink wrapped application, and want to make sure that it runs smoothly in every possible user setup
- you want to test an application against different sets of php.ini configurations, to check for possible problems in areas such as output buffering, opcode caches etc…
- you are into integration testing
There are many different setups that can be used to achieve this result (a big list is available on Gentoo docs, courtesy of Andreas Korthaus).
My preferred setup is: use a single apache instance, with a single php version installed as module, and many versions installed as cgi applications. Advantages:
- no need to rename any php file to run it with different php versions
- no need to restart the webserver or run any kind of script to switch php version
- uses less memory than multiple apache installs
The main disadvantages are:
- only 1 php version can run as an apache module, the others must limit themselves to cgi
- a very misbehaved php application can in rare cases hog or crash the webserver, and it will have to be reset before testing with other php versions
The instructions below are geared to a windows environment with Apache 2, but converting them to linux is left as trivial exercise for the sysadmin.
Continue reading Running multiple php versions on a single Apache install