How to set a PHP version per domain or per folder

Modified on Wed, 20 Mar 2024 at 03:50 PM

We support multiple PHP versions per account and domain on servers with CloudLinux. By creating a .htaccess file, you will be able to define the PHP version to be run in that folder or domain. You can create a .htaccess file using the filemanager or a FTP client.


DirectAdmin .htaccess location

For DirectAdmin, the domain folder you want to edit can be found in

/domains/yourdomain.com/public_html
or

/domains/yourdomain.com/private_html


cPanel .htaccess location

For cPanel there are multiple locations possible. Navigate to Domains and click on the Document root next to the domain where you want to change the PHP version for.


Configure the PHP version for a domain

Open or create the .htaccess file if it does not exist. Enter the following line. Replace php80 with the exact version you would like to use. E.g. if you woud like 7.1, replace it with php71. If you want 5.6, replace it with php56.


For cPanel:

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
    SetHandler application/x-httpd-alt-php80___lsphp
</FilesMatch>


For other panels (DirectAdmin and Plesk):

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
    SetHandler application/x-lsphp54
</FilesMatch>

Save the .htaccess file. The new PHP version is immediately active. Just change the last two numbers to the version you need, .e.g 54 is PHP 5.4 (without the dot).


To change the PHP settings, navigate to the PHP selector and choose the PHP version you want to manage. Do not click on Set as current version. If you do, you will change the default PHP version for the full account. Change the modules or click on Options to change the PHP options.


Note: This does not change PHP versions on command lines.


Configure the PHP version per folder

Navigate to the folder where you wish to use a different PHP version. Continue with the steps with Configure the PHP version for a domain.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article