Can I use a different PHP version per folder or subdomain?
Yes, you can. Your hosting package has one main PHP version, which you choose in DirectAdmin under Select PHP version. If a single folder or subdomain needs to run on a different version, for example an old website that doesn't work on the latest PHP yet, you can give that folder its own version with a line in .htaccess.
1. How to set it up
- In DirectAdmin, open File Manager and go to the folder that needs a different version. For a subdomain, that's the subdomain's folder, for example
domains/example.co.uk/public_html/shop. - Open the
.htaccessfile in that folder, or create it if it doesn't exist yet. - Put this line at the top and replace
81with the version you want, without a dot (so74for PHP 7.4 or81for PHP 8.1):
AddHandler application/x-httpd-php81 .php
The line applies to the folder and all folders below it. The rest of your package stays on the main version.
2. Checking that it works
Place a file named versie.php in the same folder with this content and open it in your browser:
<?php echo PHP_VERSION;
You'll then see the version that's active in that folder. Delete the file again afterwards.
3. Good to know
- Use exactly the line above. Variants you may come across online, such as
SetHandler,AddTypeorx-lsphp81, don't work on our servers. - The folder uses the PHP extensions and settings that belong to that version in Select PHP version. If the website is missing an extension, you'll usually notice it from an error message about a missing function.
- Does a website only run on an old PHP version? Have it updated in due course, by your web developer or by us: see Having a PHP upgrade done.
- Want to go back to your package's main version? Remove the line from .htaccess.
Detailed explanation with screenshots: Choosing the PHP version (Select PHP version) in the DirectAdmin manual.
