You can easily select a different PHP version for a specific directory by using a small rule in your .htaccess file.
This is useful when:
- You run multiple applications on the same hosting account
- A specific script requires a different PHP version
- You want to test a new PHP version without affecting the entire website
Step 1: Locate or create the .htaccess file
Open the directory where you want to use a different PHP version.
Then locate or create the file:
.htaccess
Example directory:
/public_html/example-folder/
Step 2: Add the PHP handler
Add the following code to the .htaccess file:
<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-lsphp84 </FilesMatch>
This example will enable PHP 8.4 for the directory.
Available PHP versions
You can replace the version number in the handler with one of the following PHP versions:
5.2 5.3 5.4 5.5 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2 8.3 8.4 8.5
Example for PHP 8.2:
<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-lsphp82 </FilesMatch>
Important notes
- The PHP version will only apply to the directory where the .htaccess file is placed
- All subdirectories will inherit this PHP version
- You can create multiple .htaccess files in different directories if needed