Knowledgebase

Changing PHP Version with .htaccess on LiteSpeed – Complete Guide Print

  • 0

Introduction:

At Prabhu Host, we provide full flexibility for developers and users to manage their PHP environments. Whether you need to test new features, maintain compatibility, or optimize performance, switching PHP versions per website or folder is simple no server-wide changes needed. You can do this using the .htaccess file on our LiteSpeed-powered servers.

Why Change PHP Versions?

PHP evolves rapidly, with each version bringing improvements in:

  • Performance

  • Security

  • New language features

Using the latest supported version is highly recommended. However, if your application requires a specific PHP version, you can apply it to a directory using .htaccess handlers without affecting other sites on your account.

How to Change PHP Version Using .htaccess

Step 1: Locate or Create the .htaccess File

  1. Navigate to the root directory of your website (commonly public_html).

  2. Look for a file named .htaccess.

    • If it doesn’t exist, create one using cPanel’s File Manager or an FTP client.

Step 2: Add the PHP Version Handler

Insert the following code into the .htaccess file:

<IfModule Litespeed>
AddHandler application/x-httpd-lsphp81 .php
</IfModule>

Replace lsphp81 with your desired PHP version handler:

  • lsphp74 = PHP 7.4

  • lsphp80 = PHP 8.0

  • lsphp81 = PHP 8.1

  • lsphp82 = PHP 8.2

If you are unsure which versions are available on your plan, check in cPanel > Select PHP Version, or contact Prabhu Host support.

Step 3: Save and Upload the File

After editing:

  • Save the .htaccess file.

  • Ensure it is uploaded to the correct directory (e.g., root folder of your site).

Step 4: Verify the PHP Version

To confirm the change:

  1. Create a new file called phpinfo.php.

  2. Add the following content:<?php
    phpinfo();
    ?>

  3. Upload it to your site.

  4. Visit yourdomain.com/phpinfo.php in a browser.

You’ll see detailed PHP environment info, including the version in use.

Important: Delete this file after checking, as it exposes sensitive configuration details.

Conclusion

Changing the PHP version using .htaccess gives you full control over your hosting environment at the directory level perfect for development, testing, or handling legacy projects. This method is especially useful if you're hosting multiple sites with different PHP requirements.

 

 

 

Was this answer helpful?
« Back