setting multiple PHP versions on one account htaccess

Cpanel hosting Solution Dedicated Server Solution DirectAdmin VPS / Server Htaccess Web Hosting

Below is an example of having multiple directory locations using different versions on PHP. The following example shows the “public_html” is using PHP 5.4, the “public_html/othersite” using PHP 5.2 and so forth.

public_html 5.4
public_html/othersite: 5.2
public_html/someothersite: 5.3
public_html/someothersite/yetanother: 5.4

Using the Default PHP version

To use the system default PHP, use the following in .htaccess:

# Use system PHP5 as default
AddHandler application/x-httpd-php5 .php
This will make the specific directory use the System default PHP version.

Changing the PHP version per directory

Depending on what version of PHP you want to use, you will need to placed the following code in the .htaccess of the directory you want to change the PHP version for. Below is the code you need for each PHP version.

PHP 5.2

# Use PHP 5.2 as default
AddHandler application/x-httpd-php52 .php
PHP 5.3

# Use PHP 5.3 as default
AddHandler application/x-httpd-php53 .php
PHP 5.4

# Use PHP 5.4 as default
AddHandler application/x-httpd-php54 .php
PHP 5.5

# Use PHP 5.5 as default
AddHandler application/x-httpd-php55 .php
Once you add the appropriate version code to your .htaccess your site in that directory will use that version of PHP.

Important! If you have PHP errors after adding the .PHP version code to the directory .htaccess, you may need the php.ini for that particular version uploaded to the directory and the recursive path added in order for the correct version of the php.ini to load. If there is no php.ini specific to the version of PHP you are using in the directory where the version code is added, the server will use the default php.ini. This could cause a newer php.ini version to used instead of the older php.ini version, which can cause an issue in some cases.

Using a PHP specific version of php.ini.

The following code will direct the server to the particular php.ini file. In this case the path goes to the public_html directory. This is called the recursive path.

suPHP_ConfigPath /home/USER/public_html

To point your domain to a php.ini in a subfolder you would do the following:

suPHP_ConfigPath /home/USER/public_html/foldername

This allows a php.ini to be stored in the sub directory particularly for your PHP version in that directory. Note! If you need an older version of the php.ini file restored to a specific directory, you can specify the path to whatever version you are looking for like the following.

suPHP_ConfigPath /usr/local/lib
suPHP_ConfigPath /opt/php52/lib
suPHP_ConfigPath /opt/php54/lib
Otherwise, you can contact tech support to have them restore the specific php.ini version to the folder you need it in.

Checking your changes

You can check to see if any changes you made took place by placing a phpinfo page in the folder area you are working on

PHP Configuration Plugin

If you ever encounter problems with the way your server handles PHP packages, it may be helpful to view and/or modify your server’s PHP configuration. For example, if your site uses an older script that is incompatible with a newer PHP version, you may want to configure the site to use an older version of PHP; otherwise, you should be sure that your site’s scripts are updated to the latest version available to avoid any issues with PHP updates.

Update PHP Version for a Site

The PHP Configuration plugin in cPanel allows users on Shared and Reseller servers to easily enable a specific PHP version for a site without having to manually add a handler to the .htaccess file. To update the PHP version for a site:

Log into cPanel.
In the Advanced section, click on the PHP Configuration icon.

Navigate to the directory for which you’d like to update the PHP version.
From the drop-down menu, select a specific version of PHP or one of the following options:
Select PHP Version
No custom PHP Handler (Sys Default) – This option will process the .php file extension using the server default, which is not necessarily the latest version of PHP. (The PHP System Default is displayed at the top of the plugin page.)
PHP Cur – This option will automatically process the .php file extension using the latest stable version of PHP on the server.
Caution: If your site’s scripts rely on older functions of PHP which are no longer available in the latest stable version being used on the server, you may encounter compatibility issues when PHP Cur is automatically updated.
Click Update.
When using the PHP Configuration plugin, updates are applied recursively. This means any update you apply to a directory will also apply to all sub-directories, unless you apply a different directive to one of those sub-directories. Therefore, to use a different PHP version for an addon domain, you would need to navigate to the document root for the addon domain and select the appropriate version of PHP.

Leave a Reply

Your email address will not be published. Required fields are marked *