PHP settings: version, extensions, upload size and memory limit

How to Use a Different PHP Version for a Subdomain or Folder

By

·

,

Your hosting account has one main PHP version, which applies to your main domain and to every subdomain and addon domain. If one site needs a different version, for example an old app that only runs on PHP 7.4 while the rest of your sites use PHP 8.3, you can set it for that one folder with a few lines in its .htaccess file. The change applies immediately and you do not need to contact us.

Set the version for one subdomain or folder

  1. Log in to cPanel and open File Manager.
  2. Go to the folder of the subdomain or folder that needs the other version, for example public_html/shop, or the folder you chose when you created the subdomain.
  3. Open the .htaccess file in that folder, or create one. To see files that start with a dot, click Settings at the top right of File Manager and tick Show Hidden Files.
  4. Add these lines at the top of the file:
<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
    SetHandler application/x-httpd-alt-phpXX___lsphp
</FilesMatch>
  1. Replace XX with the version number without the dot, as in the table below.
  2. Save the file. The new version applies to that folder straight away.
PHP versionWrite in place of XX
PHP 7.474
PHP 8.181
PHP 8.282
PHP 8.383
PHP 8.484

Use a version that appears in the version list of Select PHP Version in your cPanel. A version that is not in that list will not work.

Check that it works

For a WordPress site, go to Tools, then Site Health, then Info, and open Server. For any other site, create a file named info.php in the same folder with the line below, open it in your browser (for example shop.yourdomain.com/info.php), check the PHP version at the top, and delete the file when you are done.

<?php phpinfo();

Good to know

  • The rest of your account keeps its main version. You change that one in Select PHP Version, not in .htaccess.
  • The lines also apply to the folders inside that folder, unless one of them has its own lines with another version.
  • The extensions you tick in Select PHP Version are for your main version. In info.php, check that the extensions your site needs are loaded for the other version too. If one is missing, message us on Telegram with your domain name.
  • To go back to the main version, delete the lines from the .htaccess file and save it.

📘 Why not Per Domain Settings?

Select PHP Version has a Per Domain Settings tab, but it needs Site Isolation, which is not enabled on our servers, so its switches stay off. The .htaccess lines above do the same job.

This works on Premium (cPanel) hosting. On Standard hosting (DirectAdmin), message us on Telegram with your domain name and the version you need.