![using multiple php versions hero image](https://www.inmotionhosting.com/support/wp-content/uploads/2021/08/using-multiple-php-versions-1024x538.png)
When using different software on one account, you may need to use one version of PHP while running multiple PHP versions on different domains. For example, you can have PHP 5.4 for the site in public_html and then use PHP 5.2 in a subdirectory. Here is how to use any combination of other PHP versions in any directory when web hosting with PHP.
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 .php5
This will make the specific directory use the System’s default PHP version.
Using Multiple PHP Versions
Depending on what version of PHP you want to use, you will need to place 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.3
# Use PHP 5.3 as default
AddHandler application/x-httpd-php53 .php .php5
PHP 5.4
# Use PHP 5.4 as default
AddHandler application/x-httpd-php54 .php .php5
PHP 5.5
# Use PHP 5.5 as default
AddHandler application/x-httpd-php55 .php .php5
PHP 5.6
# Use PHP 5.6 as default
AddHandler application/x-httpd-php56 .php .php5
PHP 7.0
# Use PHP 7.0 as default
AddHandler application/x-httpd-php70 .php .php5
PHP 7.1
# Use PHP 7.1 as default
AddHandler application/x-httpd-php71 .php .php5
PHP 7.2
# Use PHP 7.2 as default
AddHandler application/x-httpd-php72 .php .php5
PHP 7.3
# Use PHP 7.3 as default
AddHandler application/x-httpd-php73 .php .php5
PHP 7.4
# Use PHP 7.4 as default
AddHandler application/x-httpd-php74 .php .php5
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 be 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 subdirectory, 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.
Using the MultiPHP Manager to Change the PHP Version
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. You can then view the settings to ensure they are set correctly.
So, now can I control the PHP version for each website in the same account?
Yes, that is what this guide covers. Are you having any problems or issues?
I note the final answer says you can now change one domain to a higher version of PHP. I tried adding the line to my .htaccess taking it to PHP7, but I ended up generating download boxes, as indicated.
Also, is there any reason not to just take my entire site to PHP7?
If you are using a cPanel server, then I recommend you use the MultiPHP Manager to manage which version of PHP your websites use. When using this tool, cPanel automatically writes the necessary .htaccess code in the directories of your domains, as they are configured in cPanel. Therefore, it is not recommended (anymore) that you manually modify PHP versions using the .htaccess file code as outlined in this article. I hope this helps!
Hi,
Is this also possible for subdomains? Since the subdomain is “outside” of the public_html folder I had to create a .htaccess file and then I pasted the code
into it without anything else but it still won´t allow me to install this software which require a php version lesser than 7.0 https://www.softaculous.com/softaculous/apps/others/Open_Journal_Systems
It is possible for subdomains to have their own PHP version set in their respective directory’s .htaccess file. However, it’s more likely that Softaculous is using the server’s main PHP version (rather than the subdomain’s local .htaccess file’s configured PHP version) and will continue to detect the PHP 7.0 version. Do you have root access to change the server’s default PHP version?
IS php7.0 currently supported under Reseller accounts
Yes, you will be able to find it in cPanel accounts under Software & Services > PHP Configuration.
I have hostgator and they’ve given me similar instructions but it doesn’t seem to work. You see my server is set to 5.4 but home directory is to 5.2.17 via .htacess. So when I add an .htacess file to home/public_html/sites/ directory with 5.4 it tries to download the phpinfo file rather than view it. Am I doing something wrong? Here’s what I have in the home directory .htaccess
#Use PHP52 as default
AddHandler application/x-httpd-php52 .php
<IfModule mod_suphp.c>
suPHP_ConfigPath /opt/php52/lib
</IfModule>
Here’s what I have in the home/public_html/sites/ directory .htaccess
AddHandler application/x-httpd-php54 .php
<IfModule mod_suphp.c>
suPHP_ConfigPath /opt/php54/lib
<Files php.ini>
order allow,deny
deny from all
</Files>
</IfModule>
Anyhelp would be appreciated
Hello Dave,
Our configuration may be different at InMotion but basically we do allow you to run multiple versions of PHP, but this is typically done per cPanel account – not within one account . The code above allows you to use different versions of php, but the older ones UNDER the newest version. I hope that makes sense.
We use a PHP version switcher in the cPanel – but again, it applies to the ENTIRE cPanel account – not to invdividual sites inside one cPanel account.
You should be able to set your server to 5.4 and then your older sites using version 5.2 should still be okay.
I hope that helps to answer your question! If you require further assistance, please let us know!
Regards,
Arnel C.
Can I assume that the same applies to PHP 7.0 like this?
Hello Drake,
That would be the case as long as that version of PHP is installed on the server you are attempting this on.
Best Regards,
TJ Edens
After many frustrating hours of getting downloads , and being told it is possibly my application problem I prepared a sepearate cpanel with just one file index.php containg <?php phpinfo.php ?> demonstrating that the switcher did not work on my account.
The fourth inmotion helpdesk agent, Nathan S, then finally cleared the problem. He wrote “I just had to tweak a couple of the file paths for the PHP handlers due to some recent cPanel updates. I’ve tested the switcher and its working properly now. Can you check it on your end and make sure for me?” which it did on all cpanels.
So, it is not necessarily a clear-cut and easy transition as described in the post above.
Hello Anton,
It should be as simply as cutting and pasting. I am sorry it was not that way. We will check and make sure any changes are made so that it is once again that simple. Thank you for letting us know there is a discrepancy in the information.
Kindest Regards,
Scott M
Arnel,
Thanks for your reply. It didn’t dawn on me until far too late that I have created some confusion. I appreciate the help of the inmotionhosting.com staff, but I am actually hosting with someone else. (They refered me here when I asked for help.) I creaeted a phpinfo.php file which says the Server API is CGI/FastCGI. That means it’s using suPHP, right?
I greatly appreciate all of the help,
Daniel
Hello Daniel,
Thank you for contacting us, we are happy to help. Yes, that is correct. If the “Server API” lists CGI, then suPHP is installed.
If you have any further questions, feel free to post them below.
Thank you,
John-Paul
TJEdens,
Thanks for your comment. I am on a dedicated server. I had to go through the WHM to change the PHP, but that broke most of the installs on that server. Does this (being on a dedicated server) indicate that I cannot run multiple versions of php?
Thanks again,
Daniel
Hello Daniel,
Sorry for the ongoing issue with the PHP version change. As long as you are using suPHP, then you can request that the option be added to your server. You would need to submit a ticketed request to live technical support team and they can do that for you. This would add the option to your cPanel to switch between the PHP versions.
I hope this helps to answer your question, please let us know if you require any further assistance.
Regards,
Arnel C.
I am having the same problem that Bryan was, only my support told me I had to do it myself. My default php is 5.3, but I want to use 5.4 or higher on a directory. Whenever I change the .htaccess I get download boxes. What am I doing wrong?
Hello Daniel Titus,
I do apologize for that response as it was not deserved. Generally when you get the download boxes then either the server is not configured to allow multiple PHP versions or the software you are running is specific to the version you are one. All of our shared servers are able to move between PHP versions within the cPanel.
Best Regards,
TJ Edens
Please disregard – for others experiencing the same issue, I had to call support and request this feature to be added (VPS). It is now working properly.
Doesn’t work…doing this just starts giving me download boxes for all of my files. This article needs to be updated.
I used
AddHandler application/x-httpd-php55 .php
This is outdated, can you update your article?
Important! You can only go backwards. You cannot use a newer version of PHP on an older PHP server. You will need to have newest version of PHP on the server to do this.
One of your Support Reps just told me this:
The PHP switcher should work for 5.5, if using suPHP.
Yes, you are able to use this for 5.5 as well.
You can now go to a higher version using this method as well. I have updated the article to remove this warning.
Can you update this article and add php 5.5 as well?
AddHandler application/x-httpd-php55 .php