Running Multiple Versions of PHP
On some servers, you may have an older script that requires PHP 4, but another account whose scripts require PHP 5. In the past, installing a separate copy of PHP using FastCGI was the most effective method. However, cPanel 11 and the EasyApache 3 utility include a built-in method for running two versions of PHP, and each cPanel account will have an option to switch between the two versions within their cPanel dash board.
Note: For most VPSes, only one version of PHP is required. PHP 5 is the recommended version, as PHP 4 is not undergoing any further development. Before proceeding with this, ask yourself if you really need two versions of PHP.
To start with, you must be familiar with the compiling Apache and PHP using EasyApache. Visit HOWTOUpdateApache HOWTOApacheAdvanced for more information. Also, please make note of the official cPanel Apache Configuration Guide.
Background info: PHP is compiled into Apache as a DSO module, that is, it's runs as part of Apache. PHP can also be configured to run through the CGI interface, as well as FastCGI and suPHP. Only one version of PHP can operate as a DSO module. Running a separate version must execute through CGI, FastCGI, or suPHP. You can also run both versions external to Apache using CGI/FastCGI/suPHP.
(note, suPHP and CGI/FastCGI will cause your PHP scripts to be executes as the User ID of the script owner instead of the web server. Read this article for details on adjusting permissions for files and directories for use with suPHP/CGI).
Compiling PHP and Apache
At the PHP version screen, you have two options: PHP 4 and PHP 5.
Select both versions, and proceed to the next screen.

You will then have the option of selecting your PHP minor versions:

On the Short Options list, be sure to select "Mod SuPHP" at the top of the list:

You can Save and Build now, or you configure specific PHP modules for each version of PHP in the Exhaustive Options List.
Configuring PHP
Once you've built Apache and PHP above, you can now configure how you want to run PHP.
The recommended method is to use suPHP rather than CGI. You can run both as suPHP, or use one version as DSO (apache module) and the other as suPHP.
There is a command-line utility to configure PHP handling, but the documentation and syntax is somewhat obtuse.
The simplest method to configure PHP is to use WHM -> Service Configuration -> Configure PHP and SuExec.
You can select your default PHP Version (PHP 5 recommended) and then select which module to use for each version (DSO, suPHP, CGI, none). Use the drop-down menu to select the handling:

Recommended option is to use PHP 5 as default, and suPHP for both versions. If you need to run one as a DSO (built into Apache), select your default version to use as DSO and the secondary PHP as suPHP.
Once this is configured, your cPanel account holders can login to cPanel and change their version (PHP 5 or PHP 4) in cPanel -> Advanced Configuration -> PHP Configuration.
How to configure and update Apache
Advanced Apache/PHP Configuration
Back to VPS
Back to Main
There are no comments on this page. [Add comment]