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 用戶發現這個有用
這篇文章有幫助嗎?

相關文章

如何使用 cPanel 下载备份?(视频)

使用cPanel下载备份是一个简单的过程。以下是帮助您安全下载网站备份的逐步指南: 第一步:登录cPanel 打开您的网页浏览器。...

如何生成Sapna备份并发送到FTP服务器? (视频)

生成cPanel备份并将其发送到FTP服务器是一个简单的过程。以下是具体步骤: 第1步:登录cPanel...

如何在 cPanel 中恢复备份?(视频)

在 cPanel 中恢复备份是一个简单的过程,可以高效地恢复您的网站数据。以下是恢复备份的分步指南: 第一步:登录 cPanel 打开您的网页浏览器,访问...

如何在 cPanel 中更改账户密码?(视频)

在cPanel中更改账户密码非常简单,只需几个步骤即可完成。请按照以下说明操作。 第一步:登录cPanel...

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

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