Kualo / docs
On this page

Setting PHP versions per folder / website using .htaccess (AddHandler)

Use an AddHandler directive in .htaccess to run different PHP versions for different folders or websites on the same hosting account.

5 min read Updated 4 Jun 2026

By default, your website runs on the PHP version set in cPanel. If you need to change the PHP version account-wide, see how to do this using the Select PHP Version tool. If your account hosts multiple websites, subdomains, or addon domains, you can set a different PHP version for each one by adding an AddHandler rule to the relevant .htaccess file.

Why set a PHP version using .htaccess?

There are several reasons you might want to do this:

  • Compatibility - some older scripts require an older PHP version, while newer applications may need the latest release.
  • Testing and development - you may want to test your site against a different PHP version before changing the global setting.
  • Folder-specific configuration - you might need different PHP versions for different parts of your site, for example a legacy app in one folder and a modern app in another, or a staging copy of your site running on a newer PHP release.

Older PHP versions on our servers are security-hardened, so even if they are no longer officially supported upstream, they remain secure. That said, running an older PHP version may indicate that your application is outdated. We strongly recommend keeping your software up to date and following current security best practices.

How to set a PHP version using .htaccess

The .htaccess file applies settings to the folder it sits in and all its subfolders. Adding an AddHandler rule at the root of your site applies it to the entire site. If you only want to change the PHP version for a specific folder - such as an addon domain, subdomain, or staging environment - place the .htaccess file inside that folder instead.

Add the following line to the relevant .htaccess file, replacing XX with the two-digit version number:

AddHandler application/x-lsphpXX .php

For example, to use PHP 8.1:

AddHandler application/x-lsphp81 .php

Examples

If you need different PHP versions for different parts of your site, create a separate .htaccess file in each relevant folder. Do not try to set multiple PHP versions in a single .htaccess file.

Example 1: PHP 8.0 for the whole site

Add this to /public_html/.htaccess:

AddHandler application/x-lsphp80 .php

Example 2: PHP 5.6 for a legacy application

Create /public_html/legacy/.htaccess and add:

AddHandler application/x-lsphp56 .php

Example 3: PHP 8.2 for a staging environment

Create /public_html/staging/.htaccess and add:

AddHandler application/x-lsphp82 .php

Supported PHP versions

The following versions are available with the AddHandler directive. This list was correct at the time of writing - check cPanel's Select PHP Version tool for the current list on your account.

AddHandler application/x-lsphp56 .php   # PHP 5.6
AddHandler application/x-lsphp70 .php   # PHP 7.0
AddHandler application/x-lsphp71 .php   # PHP 7.1
AddHandler application/x-lsphp72 .php   # PHP 7.2
AddHandler application/x-lsphp73 .php   # PHP 7.3
AddHandler application/x-lsphp74 .php   # PHP 7.4
AddHandler application/x-lsphp80 .php   # PHP 8.0
AddHandler application/x-lsphp81 .php   # PHP 8.1
AddHandler application/x-lsphp82 .php   # PHP 8.2
AddHandler application/x-lsphp83 .php   # PHP 8.3

Verifying your PHP version

  1. Create a new file in your website's root folder - for example, php_version.php (choose your own name).

  2. Add the following content:

    <?php
    phpinfo();
    ?>
    
  3. Save the file and open it in your browser, for example https://yourdomain.com/php_version.php.

  4. Check the PHP Version shown at the top of the page.

Delete this file immediately once you have confirmed the PHP version. Leaving it accessible exposes sensitive server configuration details to anyone who visits the URL.

Editing .htaccess

You can edit the .htaccess file using any of the following methods.

cPanel File Manager

  1. Log in to cPanel and open File Manager.
  2. Navigate to the folder where the .htaccess file should be located.
  3. Click Settings (top-right corner) and enable Show Hidden Files (.dotfiles), as .htaccess files are hidden by default.
  4. Locate and edit the .htaccess file.
  5. Save your changes.

FTP/SFTP

  1. Connect to your server using an FTP client such as FileZilla.
  2. Navigate to the directory containing the .htaccess file.
  3. Download the file to your local machine.
  4. Open it in a text editor, make your changes, and save.
  5. Upload the modified file back to the same directory.

SSH

  1. Connect to your server via SSH.

  2. Navigate to the correct directory:

    cd /home/youruser/public_html/yourfolder
    
  3. Edit the file using nano or vim:

    nano .htaccess
    
  4. Make your changes and save.

If no .htaccess file exists yet, create a new file named exactly .htaccess (no extension) in the relevant directory using any of the methods above.

Important notes

  • Migrating from another host - your existing .htaccess may contain PHP version directives that do not work on our servers. Other hosts use methods such as AddType, SetEnv, or .user.ini files, which may not be compatible here. If you experience issues after migrating, review your .htaccess and replace any existing PHP version settings with the AddHandler directive shown above.
  • PHP extensions and settings - when you set a PHP version via .htaccess, the server's default extensions and settings for that version apply. To customise them, go to cPanel, open Select PHP Version, choose the version you have set in .htaccess, and adjust extensions and settings as needed. Do not click Set as current, as that will change the default PHP version for your entire account. See our companion article on the Select PHP Version tool for more detail.
  • Testing before making changes - if you are unsure whether a PHP version change will affect your site, test in a staging environment first, or back up your .htaccess file before editing.
  • .htaccess overrides account-wide settings - a PHP version set in .htaccess takes precedence over the default version in cPanel. If your PHP version does not appear to update after changing it in cPanel, check your .htaccess for an AddHandler directive that may be enforcing a specific version.
Was this helpful?
Your feedback helps us find gaps in the docs.
Still need a hand?
Real people, around the clock - start a chat or open a ticket and we'll help you put it right.