Skip to content

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.

  • 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.
  • 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”
  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).

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
  • Save the .htaccess file in the target directory.
  • The new PHP version takes effect immediately.
  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.