Knowledge Base

How to set up and run alternate PHP versions

This article describes how to set up and run alternate PHP versions on your account.

Most of the information in this article only applies to hosting accounts that do not use CageFS. To determine if CageFS is enabled for your account, please see this article.

Alternate PHP versions

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

Third-party plugins such as Zend Optimizer and Zend Guard are not included and not supported. However, you can install them in your home directory and use a custom php.ini file to load them as extensions. They should work, but please note that we do not provide support for these configurations. (For information about using ionCube Loader with alternate PHP versions, please see this article.)

PHP version locations

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:

  • The CGI binary that Apache uses to serve PHP-enabled web pages is /opt/php/php-version/bin/php-cgi.
  • The PHP command-line executable is /opt/php/php-version/bin/php.
  • The php.ini configuration file is /opt/php/php-version/lib/php.ini. You can use this file as the basis for a custom php.ini file. For more information about custom php.ini files, please see this article.
  • Some PHP versions have extensions, which are located in the /opt/php/php-version/lib/php/extensions directory.

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.

Enabling an alternate PHP version for web site pages

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.

Method #1: Use cPanel

For instructions about how to use cPanel to switch PHP versions, please see this article.

Method #2: Manually edit .htaccess files
This method works on all hosting accounts except for Turbo Web Hosting accounts.

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

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

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.

Using an alternate PHP version for command-line applications

To determine the command-line PHP version currently installed on your account, type the following command at the command prompt:

php -v

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:

ls /opt/php

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:

/opt/php/php-5.5.0/bin/php test.php