The information in this article only applies to accounts on cPanel servers that are running CloudLinux.
This article describes how to set the PHP version for a specific directory. Normally, when you set the PHP version in cPanel using the PHP Selector, that version is used for the entire account. However, if you want to use a different PHP version in a specific directory or a domain directory, you can do so by following this instruction.
Changing the PHP version for a directory
To change the PHP version for a specific directory, follow these steps:
- Using your preferred cPanel File Manager, create a file named .htaccess in the directory where you want to use a different PHP version.
- The .htaccess is a hidden file. If you want to view the .htaccess file is it already existed on the directory. You need turn the settings on.
- Go to the right corner of cPanel - File manager,
- Click Settings, then turn on the option "Show Hidden Files (dotfiles)" and Save it.
- While you created a new .htaccess or edit an existing .htaccess. Copy the following text:
<FilesMatch ".(php4|php5|php3|php2|php|phtml)$">
SetHandler application/x-httpd-alt-phpXX___lsphp
</FilesMatch> - Replace XX with the PHP version you want to use in the directory. You can use any PHP version that is listed in the cPanel PHP Selector. For example, to enable PHP 8.2, you would type SetHandler application/x-httpd-alt-php82___lsphp. (Make sure you do not include the period in the version number. For example, for PHP version 7.1, type 71.)
- Paste the modified text into the .htaccess file.
- Save the .htaccess file. The new PHP version takes effect immediately.
To verify the new configuration, create a PHP file that runs the phpinfo() function. Load the file in your web browser, and confirm the PHP version.