Dev License: This installation of WHMCS is running under a Development License and is not authorized to be used for production use. Please report any cases of abuse to abuse@whmcs.com

Instructions for Shared Web Hosting, Reseller Hosting and Managed Servers (running CloudLinux PHP Selector)

The running PHP version for your hosting account must be set via the page Select PHP Version in your cPanel control panel. You can also manage PHP extensions and custom PHP options via the user interface.

The user interface on the "Select PHP Version" page only permits you to set one PHP version per hosting account. However, there is a workaround where you can set a different PHP version for a sub-directory.

Step 1 - Customize your PHP version (via PHP Selector)

First, you will need to assure that your PHP environment is prepared and compatible with your site and scripts. The default settings should be suitable for WordPress and most sites, but you may want to check the system requirements of your site and scripts first, then enable any missing PHP extensions under the Extensions tab and edit any necessary PHP options under the Options tab in cPanel under Software -> Select PHP Version.

There is a separate guide on how to manage this here: Manage PHP version and configuration for your cPanel hosting account

Step 2 - Set the PHP version in the sub-directory

Navigate to the desired sub-directory for which you'd like to set a different PHP version via FTP or using the cPanel File Manager. If you use the cPanel File Manager, make sure that hidden files are shown [Settings -> Show Hidden Files (dotfiles)].

.htaccess file must exist in the sub-directory. If one does not exist, create it first and make sure to add the dot prefix at the beginning of the file name.

You need to add 3 lines of code to the top of the .htaccess file. The following code will set the sub-directory to the defined PHP version:

<FilesMatch "\.ph(p[4-8]?|tml)$">
SetHandler application/x-httpd-alt-phpXX___lsphp
</FilesMatch>

Replace phpXX with the PHP version number that you would like to use. For example, to use PHP 8.1, you would replace phpXX with php81Please use only versions that are listed in cPanel under Software -> Select PHP Version, otherwise, your PHP scripts and site will stop working.

Warning: If the applied version does not exist, any PHP file would fail to display in the browser and would be downloadable. This can be a major security concern, reason why it's important to apply the correct PHP version. If you are not sure, please create a temporary sub-directory for testing purposes first before applying any .htaccess rules to a production site.

Save the .htaccess file. The rule and the respective PHP version will apply with immediate effect.

Optional Step 3 - Check the running PHP version

To assure that the correct PHP version runs in the sub-directory, please create a random PHP file (e.g. php-version-check.php) and add the following code to it:

<?php
echo 'Current PHP version: ' . phpversion();
?>

Open the URL of this file in your browser and you will see which PHP version is running under that location.

Setting PHP Options

The PHP options should be set in cPanel under Software -> Select PHP Version -> Options for each PHP version that you plan to use.

On servers running Apache in mod_lsapi mode, it is also possible to set the PHP options using the .htaccess file, for example:

php_value display_errors on # this enables display_errors on a sub-directory
php_value error_reporting "E_ALL & ~E_STRICT & ~E_NOTICE" # this enables error reporting except PHP strict/notice warnings
php_value upload_max_filesize 150M # this enables a custom value for upload_max_filesize, default is usually 80M
php_value max_input_vars 1500 # this enables a custom value for max_input_vars, default is usually 1000

On servers running Apache in suPHP mode, setting PHP options in the .htaccess file will cause a "500 Internal Server Error".

Instructions for EasyApache and Servers without CloudLinux and PHP Selector

If the server on which your site/account is hosted does not run CloudLinux and PHP Selector, or if you prefer not to use the PHP Selector for some reason, you can use the PHP versions that are installed by EasyApache.

Please follow step 2, as mentioned above, and use the following code instead:

<FilesMatch "\.ph(p[4-8]?|tml)$">
SetHandler application/x-httpd-ea-phpXX
</FilesMatch>

Replace phpXX with the PHP version number that you would like to use. For example, to use PHP 8.1, you would replace phpXX with php81.

To find out which PHP versions are currently available, you will need to ask our technical support team. Generally, all PHP versions that are currently under active support (as listed here) should be installed on any of our servers. If you have full access to the server (e.g. on dedicated/virtual servers), you can navigate to WHM -> Software -> EasyApache 4 to see which PHP versions are currently installed.

Warning: If the applied version does not exist, any PHP file would fail to display in the browser and would be downloadable. This can be a major security concern, reason why it's important to apply the correct PHP version. If you are not sure, please create a temporary sub-directory for testing purposes first before applying any .htaccess rules to a production site.

Troubleshooting

If the site is not compatible with the applied PHP version, you may notice various errors, such as "500 Internal Server Error". Please assure that your site and scripts are compatible with the applied PHP version and update them as needed.

You can find any errors related to your site and scripts in the "error_log" files under which the site is located and under its sub-directories. You can use the cPanel File Manager to search for "error_log" files.

Should you have any difficulties applying the custom PHP version, please contact our technical support team and mention which PHP version and to which sub-directory you would like to apply.

Updated by SP on 30/03/202

Was this answer helpful? 5 Users Found This Useful (10 Votes)

Powered by WHMCompleteSolution