You may often find that you need to use different PHP versions for different websites or applications. In most cases, you can change any site's PHP version using the MultiPHP Manager in cPanel, but this only works for domains and subdomains.
This means the same PHP version will apply to any subdirectories of that domain. For example, if you have a WordPress site installed at domain.com/blog, that site will use the same PHP version applied to domain.com.
You can, however, change the PHP version of the subdirectory by modifying the .htaccess file. Here we cover the steps to manually apply a different PHP version to a subdirectory.
Related Articles
Update PHP Version with MultiPHP Manager
Edit File with File Manager
Find the Document Root of a Domain
Show Hidden Files in File Manager
Create File in File Manager
Toggle PHP-FPM for Domain in WHM
Create phpinfo Page
Change PHP Version
- Log into cPanel
- Navigate to File Manager, located under the Files section
- Navigate to the subdirectory for which you need to change the PHP version
- Locate the .htaccess file, right-click on it and click Edit
NOTE: As .htaccess starts with a "." it is a hidden file, so you will need to ensure hidden files are shown. See the guide on showing hidden files for instructions. If this file does not exist, you will need to create it. - Add the applicable SetHandler to the file
<FilesMatch "\.ph(p[4-8]?|tml)$">
REPLACE: ## with the PHP version you want to use, without the "."
SetHandler application/x-httpd-php##
</FilesMatch>
EXAMPLE: If you want to use PHP 8.2 you would add the following:<FilesMatch "\.ph(p[4-8]?|tml)$">
TIP: If the server is not using PHP-FPM, the following line can be used instead.
SetHandler application/x-httpd-php82
</FilesMatch>
AddHandler application/x-httpd-php## .php
REPLACE: ## with the PHP version you want to use, without the "."
- Click the Save Changes button
- Use a phpinfo page to confirm the PHP version has changed
Comments
0 comments
Article is closed for comments.