This is a blog about running two PHP versions on one webserver and using multiple php.ini files, this combination can be a tricky one to tackle. But luckily one we can tackle quite easily as long as one of the PHP versions is >= 5.2.7. For this example I'll be using Apache, but the webserver flavor doesn't really matter. The most important part is the "PHP_INI_SCAN_DIR" environment variable.
There could be a number of reasons to want what I'm about to talk about. In my case I have a project where I have a legacy code-base, running on a specific PHP version, and a new code-base which will be run on 5.3. Because the new code-base will be a ongoing progress of replacing the old, it first has to run side by side with the legacy code-base. So I wanted my development image to run two PHP versions.
The old code-base used php.ini settings such as a include-path, error reporting, etc. Which will be different from the new code-bas, and those can no-longer be set with the 'php_value' feature of Apaches since the PHP version we'll be using for that runs as (f)CGI rather then as module.
Installing two PHP versions in one Apache
I'm not going into depth here, I'm assuming you know how to install PHP both via a package manager and manually.
the first PHP version you want to use, I suggest to pick the most
recent version or the version you expect to be updating more frequently
via your package manager (or manually if your distribution/OS doesn't have one). And to install the (legacy) version
'manually', this will also be the version that will run in fcgi in this
example. (So in my case, I installed PHP 5.3 via a package manager and
PHP 5.2 manually.)
If you have for example a PHP 5.1.6 and PHP 5.2.11 then you need to install the PHP 5.1.6 as module and PHP 5.2.11 as (f)CGI since the PHP_INI_SCAN_DIR variable only works on 5.2.7 and up.
Secondly install the second
version. The important factor is that you specify the --prefix= and let
it be different from the the first version, I used:
Adding your PHP-CGI handler:
This is probably common ground also, but I just added it for easy copy and pasting.
I did just the same thing a week ago, and I've set the php.ini path just before compiling:
(Wich you can still overwrite using your settings, see line 609 of the mentioned source)
Also I like changing the PHP-version runtime through this simple line in the .htaccess:
AddHandler php53-cgi .php
I wonder if session problems solve setting the session_save_path ?