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 عملية بسيطة. إليك دليل خطوة بخطوة لمساعدتك في تنزيل...

كيفية إنشاء نسخة احتياطية من Sapna وإرسالها إلى خادم FTP؟ (فيديو)

إنشاء نسخة احتياطية من cPanel وإرسالها إلى خادم FTP هي عملية بسيطة. إليك الطريقة التي يمكنك بها...

كيفية استعادة النسخة الاحتياطية في cPanel؟ (فيديو)

استعادة النسخ الاحتياطي في cPanel بسيطة وتتيح لك استرجاع بيانات موقع الويب الخاص بك...

كيفية تغيير كلمة مرور حساب في cPanel؟ (فيديو)

تغيير كلمة مرور الحساب في cPanel بسيط ويمكن القيام به في خطوات سريعة. اتبع التعليمات...

كيفية تحديث معلومات الاتصال الخاصة بك في لوحة التحكم cPanel؟ (فيديو)

تحديث معلومات الاتصال الخاصة بك في cPanel أمر مهم لضمان تلقيك إشعارات حيوية حول حسابك،...