By default, when you set the PHP version in cPanel using the PHP Selector, that version applies to your entire hosting account. However, on ruachost.com, you can configure a different PHP version for a specific directory using a .htaccess file.

 

Why Change PHP Version Per Directory?

  • Run applications that require different PHP versions side‑by‑side.

  • Test compatibility with newer PHP versions without affecting your whole site.

  • Maintain legacy scripts while upgrading other parts of your application.

 

Requirements

  • Your account must be hosted on servers running CloudLinux.

  • Applies to:

    • Shared hosting accounts

    • Reseller hosting accounts

    • Turbo Web hosting accounts

    • Managed VPS and Dedicated servers activated May 2023 or later

 

Steps to Change PHP Version for a Directory

Step 1: Create/Edit the .htaccess File

  1. Navigate to the directory where you want to use a different PHP version.

  2. Create a file named .htaccess (or edit the existing one).

Step 2: Add the Handler Code

Insert the following code into the .htaccess file:

<FilesMatch ".(php4|php5|php3|php2|php|phtml)$">
    SetHandler application/x-httpd-alt-phpXX___lsphp
</FilesMatch>
  • Replace XX with the desired PHP version number (without the dot).

    • Example: For PHP 8.1 → php81

    • Example: For PHP 7.4 → php74

Step 3: Save the File

  • Save the .htaccess file in the target directory.

  • The new PHP version takes effect immediately.

 

Step 4: Verify the Configuration

  1. Create a test file named info.php in the same directory:

    <?php phpinfo(); ?>
    
  2. Visit http://yourdomain.com/directory/info.php.

  3. Confirm the PHP version displayed matches your intended version.

  4. Delete the test file afterward for security.

 

Important Notes

  • If you enabled additional PHP extensions for the default version in cPanel, check phpinfo() to confirm they are also loaded for the custom version.

  • If extensions are missing, open a support ticket with Ruachost.

  • This method only affects the directory where .htaccess is placed and its subdirectories.

Bu cavab sizə kömək etdi? 0 istifadəçi bunu faydalı hesab edir (0 səs)

Powered by WHMCompleteSolution