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 یک فرآیند ساده است. در اینجا یک راهنمای گام به گام...

چگونه می توان پشتیبان Sapna ایجاد کرد و به سرور FTP ارسال کرد؟ (ویدئو)

ایجاد یک نسخه پشتیبان cPanel و ارسال آن به یک سرور FTP یک فرآیند ساده است. در اینجا...

چگونه یک نسخه پشتیبان را در سی پنل بازیابی کنیم؟ (ویدئو)

بازگردانی نسخه پشتیبان در cPanel آسان است و به شما این امکان را می‌دهد که داده‌های...

چگونه رمز عبور حساب را در سی پنل تغییر دهیم؟ (ویدئو)

تغییر رمز عبور حساب در cPanel ساده است و می‌توان آن را در چند مرحله کوتاه انجام داد....

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

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