This article describes how to set up and run alternate PHP versions on your account.
In addition to the default PHP installation, A2 Hosting provides full, complete builds for several alternate PHP versions. These versions are built with all the common (and several uncommon) plugins and options. Every option that is in the default PHP version is also available in the alternative versions.
If a PHP version build does not include a feature that you want, you can request it. However, please note that we cannot make any promises, because other shared accounts use the builds as well. If you need further assistance, please open a support ticket with our Guru Crew on the Customer Portal at https://my.a2hosting.com.
Alternate PHP versions are installed in the /opt/php/php-version directories, where version represents the version number. Some PHP versions also have patches. For example, the Suhosin-patched version of PHP 5.3.4 is installed in the /opt/php/php-5.3.4-suhosin directory.
For each PHP version installation:
You can use these alternate PHP versions for your web site pages, as well as for command-line applications. In fact, you can even run a different version for your web site and for the command line if you want. The following procedures demonstrate how to use these alternate PHP versions.
When you enable an alternate PHP version for web pages, you do not have to change any other settings. Permissions, internal settings, and so on are handled the same way. This enables you to see the effects of a different PHP version on your code without worrying about how everything is being handled on the back end.
There are two ways to enable alternate PHP versions for your web site pages. You can use cPanel, or you can manually edit .htaccess files.
For instructions about how to use cPanel to switch PHP versions, please see this article.
The PHP version feature in cPanel simply creates or modifies the .htaccess file in your public_html directory. To change the PHP version, it links .php files to a custom MIME type. For example, to switch the PHP version to 5.4.8, cPanel adds the following lines to the .htaccess file:
<IfModule mod_suphp.c> AddHandler application/x-httpd-php-5.4.8 .php </IfModule>
Similarly, you can manually edit an .htaccess file to change your PHP version to any of the versions that are in the /opt/php directory. To do this, add the following lines and replace version with the version number:
<IfModule mod_suphp.c> AddHandler application/x-httpd-php-version .php </IfModule>
When you manually edit .htaccess files, you have complete control over the PHP version for your web site. You can even run different versions of PHP in different directories. For example, you could set PHP version 5.5.0 in the public_html/.htaccess file, and PHP version 5.4.8 in a public_html/administrator/.htaccess file. In this scenario, your entire site would run PHP version 5.5.0 except for the administrator directory, which would run PHP version 5.4.8.
To determine the command-line PHP version currently installed on your account, type the following command at the command prompt:
To run an alternate PHP version from the command line, you must specify the full path to the executable. To see the PHP versions that are available on your account, type the following command:
Each PHP version has its own directory in the /opt/php directory, and the PHP executable is located in the version's bin directory. For example, if you want to run a file named test.php from the command line using PHP version 5.5, type the following command: