How to Set the PHP Version per Folder? (Video)

Setting a specific PHP version per folder allows you to customize PHP settings for different applications or sections of your website. This is especially useful if you have multiple scripts or CMS installations requiring different PHP versions. Here’s a step-by-step guide to achieve this.


Step 1: Determine Your Hosting Environment

Before proceeding, ensure your hosting provider allows per-folder PHP version settings. This typically requires suPHP or CloudLinux PHP Selector to be enabled on the server.


Step 2: Log in to cPanel

  1. Open your browser and navigate to your cPanel login page (e.g., https://yourdomain.com:2083).
  2. Enter your username and password, then click Log in.

Step 3: Open File Manager

  1. Scroll down to the Files section in your cPanel dashboard.
  2. Click on File Manager.
  3. Navigate to the folder where you want to set a specific PHP version (e.g., /public_html/subfolder).

Step 4: Edit or Create the .htaccess File

  1. Locate the .htaccess file in the target folder. If it doesn’t exist:
    • Click + File in the File Manager toolbar.
    • Name the file .htaccess and click Create New File.
  2. Right-click on the .htaccess file and select Edit.

Step 5: Add PHP Version Configuration

  1. In the editor, add the following line to specify the PHP version for the folder:

        AddHandler application/x-httpd-alt-php81 .php

 

  • Replace php81 with the version you want to use (e.g., php74 for PHP 7.4, php80 for PHP 8.0).

    2. Save your changes by clicking Save Changes in the top-right corner.


Step 6: Test the Configuration

  1. Create a phpinfo.php file in the same folder to verify the PHP version:
    • Add the following code to the file:

                    <?php

                      phpinfo();

                     ?>

  • Save the file and visit https://yourdomain.com/subfolder/phpinfo.php in your browser.
  • Check the PHP version displayed on the page.

 

    2. Delete the phpinfo.php file after verification to prevent exposing sensitive server information.


Optional: Use a Custom php.ini File

If your hosting provider supports custom php.ini files, you can also create or edit a php.ini file in the folder to define the PHP version and other settings. Contact your hosting provider for guidance on this method.


Tips for Per-Folder PHP Configuration

  • Backup Files: Always create a backup of the .htaccess file before making changes.
  • Error Handling: If the folder throws an error after the change, verify the PHP version compatibility and syntax in the .htaccess file.
  • Consistency: Use a consistent PHP version for all related scripts in the folder to avoid conflicts.

By following these steps, you can easily set the PHP version per folder, ensuring compatibility and optimal performance for different sections of your website.

 

 

  • 123 Korisnici koji smatraju članak korisnim
Je li Vam ovaj odgovor pomogao?

Vezani članci

How to Download Backup using cPanel? (Video)

Downloading a backup using cPanel is a straightforward process. Here's a step-by-step...

How to generate a cPanel backup and sent it to FTP Server? (Video)

Generating a cPanel backup and sending it to an FTP server is a straightforward...

How to restore a backup in cPanel? (Video)

Restoring a backup in cPanel is straightforward and allows you to recover your website’s data...

How to change an account password in cPanel? (Video)

Changing an account password in cPanel is simple and can be done in a few quick steps. Follow...

How to update your contact information in cPanel? (Video)

Updating your contact information in cPanel is important to ensure you receive critical...