...

How to Set the PHP Version per Folder in cPanel

How to Set the PHP Version per Folder in cPanel

Setting the PHP version for individual folders within your cPanel account can be crucial for running different applications that require specific PHP versions. This is particularly relevant if you have a diverse set of scripts or applications hosted under a single domain. Here’s how to set the PHP version for a specific folder in cPanel:

Steps to Set PHP Version per Folder in cPanel

1. Log in to cPanel

  • Open your web browser and navigate to your cPanel login page (usually something like ).
  • Enter your cPanel username and password to log in.

2. Access the MultiPHP Manager

  • Once logged in, look for the ‘Software’ section in the cPanel dashboard.
  • Click on the ‘MultiPHP Manager’ tool. This tool is typically used for managing the PHP version for your domains and subdomains.

3. Set PHP Version for the Entire Domain (Initial Step)

  • Before setting a PHP version for a specific folder, ensure that the domain or subdomain itself is set to a default PHP version.
  • Select the domain or subdomain from the list and choose a default PHP version from the dropdown menu, then click ‘Apply’.

4. Access File Manager

  • Go back to the main cPanel dashboard and open the ‘File Manager’ under the ‘Files’ section.
  • Navigate to the public_html directory or the root directory of the domain for which you want to set a specific PHP version for a folder.

5. Locate the Specific Folder

  • Within the File Manager, navigate to the folder for which you want to set a different PHP version.
  • If the folder doesn’t exist, create it by clicking on the ‘+ Folder’ icon.

6. Create or Edit .htaccess File

  • In the target folder, look for a .htaccess file. If it doesn’t exist, create a new file named .htaccess.
  • Right-click on the .htaccess file and choose ‘Edit’ or ‘Code Edit’.

7. Add PHP Version Code

  • In the .htaccess file, you’ll need to add specific code to set the PHP version. This code can vary depending on the server and the available PHP versions. Generally, it looks something like this:
    bash
    # Use PHP 7.4
    <IfModule mime_module>
    AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
    </IfModule>
  • Replace php74 with the specific version you need (e.g., php56 for PHP 5.6, php80 for PHP 8.0, etc.).

8. Save Changes

  • After adding the code, save the changes to the .htaccess file.

9. Test the Configuration

  • To ensure that the new PHP version is active in the folder, you can create a PHP info file (info.php) containing <?php phpinfo(); ?> within the folder.
  • Access this file through a web browser to verify that the PHP version has changed.

How to Edit file in the cPanel File Manager

Important Considerations

  • Compatibility: Ensure that the application or script within the folder is compatible with the PHP version you set.
  • Server Configuration: The ability to set PHP versions per folder and the specific code required can vary depending on the server configuration and the versions of PHP available on your server.
  • Propagation Time: Changes in the .htaccess file typically take effect immediately.

Conclusion

Setting a specific PHP version for individual folders in cPanel allows for greater flexibility in managing various applications with different PHP requirements. It’s important to verify compatibility and test the configuration after making changes. As always, maintaining backups and being cautious with changes in server settings is advisable to ensure the stability and security of your websites.

 

Previous Post
How to update your contact information in cPanel
Next Post
How to Set the PHP Version per Domain using cPanel