How to switch PHP versions

From Wiki

Jump to: navigation, search

Contents

Summary

1H Ltd. has implemented a unique server setup that allows each customer to choose which version of PHP to use for his / her account. What is more, the customer can even use different PHP versions for different directories in one and the same hosting account. The PHP versions currently supported are: PHP 4.4 PHP 5.0, PHP 5.1, PHP 5.2, PHP 5.3, PHP 6.0 and a special additionally secured version of PHP 5.2 with Suhosin patch.

How to Change Default PHP Version for the Server

There are few steps that needs to be taken in order to change the default PHP version for the whole server. Note that those changes will affect the PHP version used by the Apache webserver when handling PHP files. The steps that you need to take are described below:

Via the 1H WHM Plugin

Follow these steps in order to change the default PHP version for the server:

  1. Login to WHM
  2. Go to Plugins -> 1H Software
  3. Click Configure Hive
  4. Go to the PHP settings tab
  5. Choose the desired version and click Save

Php version change.png

Manually

Simply use the following command while logged in as root on the server:

/usr/local/1h/bin/php_version.sh set [php4|php5|php51|php52|php52s|php53]

Where from [php4|php5|php51|php52|php52s|php53] you should choose the corresponding PHP version you would like set as default.

This will basically do the following:

Change the symlink for the default PHP binary in the baseos

First change the following symlink /root/baseos/usr/bin/php. This will adjust the baseos setup. Note that this step only is not directly changing the current setup that is loaded in the memory.

To switch to PHP 4.4:

ln -s /usr/local/php4/bin/php /root/baseos/usr/bin/php

To switch to PHP 5.0:

ln -s /usr/local/php5/bin/php /root/baseos/usr/bin/php

To switch to PHP 5.1:

ln -s /usr/local/php51/bin/php /root/baseos/usr/bin/php

To switch to PHP 5.2:

ln -s /usr/local/php52/bin/php /root/baseos/usr/bin/php

To switch to PHP 5.2 with Suhosin patch:

ln -s /usr/local/php52s/bin/php /root/baseos/usr/bin/php

To switch to PHP 5.3:

ln -s /usr/local/php53/bin/php /root/baseos/usr/bin/php

Than make the same change to /var/suexec/baseos/usr/bin/php - this is what is currently loaded in the memory. It is a required step in order to apply the change without restart.

To switch to PHP 4.4:

ln -s /usr/local/php4/bin/php /var/suexec/baseos/usr/bin/php

To switch to PHP 5.0:

ln -s /usr/local/php5/bin/php /var/suexec/baseos/usr/bin/php

To switch to PHP 5.1:

ln -s /usr/local/php51/bin/php /var/suexec/baseos/usr/bin/php

To switch to PHP 5.2:

ln -s /usr/local/php52/bin/php /var/suexec/baseos/usr/bin/php

To switch to PHP 5.2 with Suhosin patch:

ln -s /usr/local/php52s/bin/php /var/suexec/baseos/usr/bin/php

To switch to PHP 5.3:

ln -s /usr/local/php53/bin/php /var/suexec/baseos/usr/bin/php

Alter the httpd.conf file to reflect the changes

In the Apache web server configuration file (/etc/httpd/conf/httpd.conf) adjust the file handler for PHP files. You should the corresponding line depending on the PHP version you would like to use:

To switch to PHP 4.4:

AddHandler application/x-httpd-php4 .php .php4 .php3

To switch to PHP 5.0:

AddHandler application/x-httpd-php5 .php .php5 .php4 .php3

To switch to PHP 5.1:

AddHandler application/x-httpd-php51 .php .php5 .php4 .php3

To switch to PHP 5.2:

AddHandler application/x-httpd-php52 .php .php5 .php4 .php3

To switch to the secure PHP 5.2 with Suhosin patch:

AddHandler application/x-httpd-php52s .php .php5 .php4 .php3

To switch to PHP 5.3:

AddHandler application/x-httpd-php53 .php .php5 .php4 .php3

DirectAdmin Specific

If you are using DirectAdmin for your server, there is a chance that your webserver is utilizing the inclusion of an additional configuration file that sets default PHP handler for each PHP script execution. As this is setup to match all standard extensions for PHP files, the custom rule you are adding inside an .htaccess file should look like:

<FilesMatch "\.(inc|php|php3|php4|php5|php6|phtml|phps)$">
AddHandler application/x-httpd-php53 .php .php5 .php4 .php3
</FilesMatch>

NB: The example above is for PHP version 5.3.

Important: Note that the last line of this type that is present in the httpd.conf file is the one that will be loaded. In other words if you have added consecutively:

AddHandler application/x-httpd-php51 .php .php5 .php4 .php3
AddHandler application/x-httpd-php52s .php .php5 .php4 .php3
AddHandler application/x-httpd-php4 .php .php4 .php3

The last one (in bold) will be loaded and thus the version loaded will be PHP 4.

How to Change the PHP Version per User/Directory

Using the 1H cPanel plugin

You can find detailed instructions how to use the 1H cPanel plugin for managing PHP version here.

The main benefit of the plugin is that it provides your clients with simple GUI which allows to them to alter the PHP version for each directory under his account.

Manually

In order to change the PHP version for an account, follow these steps. Go to cPanel, File Manager and choose "Web Root (public_html/www)". There create a new file (or edit the existing one) called .htaccess and add the following line:

To switch to PHP 4.4:

   AddHandler application/x-httpd-php4 .php .php4 .php3

To switch to PHP 5.0:

   AddHandler application/x-httpd-php5 .php .php5 .php4 .php3

To switch to PHP 5.1:

   AddHandler application/x-httpd-php51 .php .php5 .php4 .php3

To switch to PHP 5.2:

   AddHandler application/x-httpd-php52 .php .php5 .php4 .php3

To switch to PHP 5.3:

   AddHandler application/x-httpd-php53 .php .php5 .php4 .php3

To switch to the secure PHP 5.2 with Suhosin patch:

   AddHandler application/x-httpd-php52s .php .php5 .php4 .php3


This setting will apply recursively to all sub-directories. In case you'd like to have a different version of PHP in a sub-directory, create a new .htaccess file in it with the directive for the desired PHP version in it.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox