Changing the PHP version for a specific directory
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?
Section titled “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
Section titled “Requirements”-
Your account must be hosted on servers running CloudLinux.
-
Applies to:
- Shared hosting accounts
- Reseller hosting accounts
- Managed VPS and Dedicated servers activated May 2023 or later
Steps to Change PHP Version for a Directory
Section titled “Steps to Change PHP Version for a Directory”Step 1: Create/Edit the .htaccess File
Section titled “Step 1: Create/Edit the .htaccess File”- Navigate to the directory where you want to use a different PHP version.
- Create a file named
.htaccess(or edit the existing one).
Step 2: Add the Handler Code
Section titled “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
XXwith the desired PHP version number (without the dot).- Example: For PHP 8.1 →
php81 - Example: For PHP 7.4 →
php74
- Example: For PHP 8.1 →
Step 3: Save the File
Section titled “Step 3: Save the File”- Save the
.htaccessfile in the target directory. - The new PHP version takes effect immediately.
Step 4: Verify the Configuration
Section titled “Step 4: Verify the Configuration”-
Create a test file named
info.phpin the same directory:<?php phpinfo(); ?> -
Visit
http://yourdomain.com/directory/info.php. -
Confirm the PHP version displayed matches your intended version.
-
Delete the test file afterward for security.