Setting a specific PHP version for specific websites, subfolders, or subdomains.
Steps to Change PHP Version
You can update the PHP version applicable to your hosting plan directly in zPanel.
If you'd like to change the PHP version for a specific domain, subdomain, or subfolder, you can do so by adding a line of code to the .htaccess
file, as explained below ????
Step 1 - Open the .htaccess File
-
Go to Websites → Dashboard, search for File Manager on the sidebar, and click on it.
-
Access the folder to which you would like to apply a different PHP version:
-
For a domain, access its
public_html
folder. -
For a subdomain, the corresponding folder will be inside the domain's
public_html
folder. -
For a specific folder, go to the desired folder's path. Once in the correct location, open the
.htaccess
file by double-clicking on it.
-
-
If the
.htaccess
file doesn't exist, you can create it directly in the file manager. Make sure to include a dot (.) at the beginning of the filename.
Step 2 - Edit the .htaccess File
Add the following code to the very beginning of your .htaccess
file:
<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
SetHandler application/x-lsphp74
</FilesMatch>
Make sure to replace the application/x-lsphp74
portion of the code with the version that you would like to use. Check this table for the possible values:
PHP Version | Code |
---|---|
7.3 | application/x-lsphp73 |
7.4 | application/x-lsphp74 |
8.0 | application/x-lsphp80 |
8.1 | application/x-lsphp81 |
8.2 | application/x-lsphp82 |
8.3 | application/x-lsphp83 |
It is recommended to use only PHP version 7.3 or higher. Lower versions are deprecated and can generate security risks and performance issues on your website.
Notes
-
To check if the change was applied correctly, you can create a
phpinfo.php
file. -
Using this method to change the PHP versions will not include PHP extensions and options.
-
Using the
php -v
command on SSH will show the PHP version of the hosting plan, not the domain or subdomain.