QuicksearchShow tagged entriesCategories |
Tuesday, November 3. 2009Multiple PHP versions on one webserverIntroductionThis 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. The whyThere 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 ApacheI'm not going into depth here, I'm assuming you know how to install PHP both via a package manager and manually. Install 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: --prefix=/usr/local/php52. Adding your PHP-CGI handler:This is probably common ground also, but I just added it for easy copy and pasting. <IfModule alias_module>
ScriptAlias /cgi-bin-php/ "/usr/local/php52/bin/" </IfModule> <Directory "/usr/local/php52/bin/"> AllowOverride All Options None Order allow,deny Allow from all </Directory> Vhost config:The virtual host config I'm using has the
"interesting" part of this blog article, and that is the
'PHP_INI_SCAN_DIR'. (Currently PHP 5.3 doesn't support multiple paths to
scan for php.ini files. But hopefully that is added soon, it is
available in PHP 6.) By issuing 'SetEnv PHP_INI_SCAN_DIR
"/path/to/ini/directory/"' you let PHP 'know' to look there for the
php.ini, rather then the default location. (For those of you who are
curious, check line 606 of:
http://svn.php.net/viewvc/php/php-src/trunk/main/php_ini.c?revision=289667&view=markup)
<virtualhost *:80> ServerAdmin me@myhost ServerName myapplication.myhost # Path to website/project's document root DocumentRoot /mnt/hgfs/projects/myapplication/www # Set the environment var for PHP to look for php.ini's SetEnv PHP_INI_SCAN_DIR "/mnt/hgfs/projects/myapplication/ini" AddHandler php-script .php Action php-script /cgi-bin-php/php-cgi .. </virtualhost> All you need to do now is make sure you have project specifc php.ini files in their "/mnt/hgfs/projects/$x/ini" directories. Do note that you need to copy the *entire* php.ini there, not just one with replacement settings because the original php.ini is no longer used. Trackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
Might only be problems with sessions being shared among the 2 php version or not?
Session sharing is no problem, just make sure you set the correct session cookie parameters [1] and if you use Suhosin (Why?!) disable the docroot encryption [2]
[1] - http://docs.php.net/manual/en/session.configuration.php#ini.session.cookie-domain [2] - http://www.hardened-php.net/suhosin/configuration.html#suhosin.session.cryptdocroot
Nice Idea!
I did just the same thing a week ago, and I've set the php.ini path just before compiling: ./configure --prefix=/usr/share/php53\ --with-config-file-path=/etc/php53/apache2\ --with-config-file-scan-dir=/etc/php53/conf.d\ --[...] (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 ?
Mark you might want to check out IIS7. It is extremely simple to run two version of PHP side by side. Just create a php handler on the virtual dir to point to another php binary and there you go.
Hey Bram!
How does that work with the configuration? Besides running the version we needed, how do we solve the configuration options?
Why not just use somthing like that ?
PHPIniDir "E:/php5" php_value extension_dir "E:/php5/ext/" |
Calendar
|
||||||||||||||||||||||||||||||||||||||||||
