Hosting Guide

How to set PHP version per directory

This advanced guide shows you how to run different PHP versions in different folders on your Ecenica hosting account. This is useful for testing new PHP versions on a staging site while keeping your live site on a stable version.

Most users should use PHP Selector instead: If you simply want to change the PHP version for your entire website or hosting account, use PHP Selector instead—it’s much simpler and recommended for most situations.


Before You Start: Which Server Type Do You Have?

Ecenica hosting uses two different web server types, and the setup method differs for each. You need to know which one you’re on before proceeding.

How to Check Your Server Type

  1. Log in to your Ecenica Dashboard
  2. Go to your hosting service
  3. Look for Web Server in your service details

You’ll see either:

  • LiteSpeed (most common on newer hosting)
  • Apache (older hosting accounts)

Not sure? Most Ecenica hosting accounts created after 2024 use LiteSpeed. If you can’t find this information, contact support and we’ll let you know.


Quick Navigation

Choose your server type:

→ I have LiteSpeed hosting (Most Ecenica customers)
→ I have Apache hosting (Older accounts)


Set PHP Version Per Directory on LiteSpeed

Most Ecenica hosting accounts use LiteSpeed servers. Follow these steps:

Steps

  1. Open the .htaccess file in the directory where you want to set a different PHP version
  2. Copy one of the code blocks below
  3. Paste it at the top of your .htaccess file
  4. Save the file

LiteSpeed PHP Version Codes

Choose the PHP version you want to use in that directory:

PHP 8.4

AddHandler application/x-httpd-alt-php84 .php .php8 .phtml

PHP 8.3

AddHandler application/x-httpd-alt-php83 .php .php8 .phtml

PHP 8.2

AddHandler application/x-httpd-alt-php82 .php .php8 .phtml

PHP 8.1

AddHandler application/x-httpd-alt-php81 .php .php8 .phtml

PHP 8.0

AddHandler application/x-httpd-alt-php80 .php .php8 .phtml

PHP 7.4

AddHandler application/x-httpd-alt-php74 .php .php7 .phtml

Example Use Case

Scenario: Your main website is in public_html running PHP 8.1, but you want to test PHP 8.3 in your staging site at public_html/staging.

Solution:
1. Navigate to public_html/staging
2. Edit the .htaccess file in that folder
3. Add the PHP 8.3 code block at the top
4. Save

Now public_html uses PHP 8.1, while public_html/staging uses PHP 8.3.


Set PHP Version Per Directory on Apache

If you have an Apache-based hosting account, follow these steps:

Steps

  1. Open the .htaccess file in the directory where you want to set a different PHP version
  2. Copy one of the code blocks below
  3. Paste it at the top of your .htaccess file
  4. Save the file

Apache PHP Version Codes

Choose the PHP version you want to use in that directory:

PHP 8.4
# php -- BEGIN cPanel-generated handler, do not edit
# Set the "alt-php84" package as the default "PHP" programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-alt-php84___lsphp .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
PHP 8.3
# php -- BEGIN cPanel-generated handler, do not edit
# Set the "alt-php83" package as the default "PHP" programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-alt-php83___lsphp .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
PHP 8.2
# php -- BEGIN cPanel-generated handler, do not edit
# Set the "alt-php82" package as the default "PHP" programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-alt-php82___lsphp .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
PHP 8.1
# php -- BEGIN cPanel-generated handler, do not edit
# Set the "alt-php81" package as the default "PHP" programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-alt-php81___lsphp .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
PHP 8.0
# php -- BEGIN cPanel-generated handler, do not edit
# Set the "alt-php80" package as the default "PHP" programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-alt-php80___lsphp .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
PHP 7.4
# php -- BEGIN cPanel-generated handler, do not edit
# Set the "alt-php74" package as the default "PHP" programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-alt-php74___lsphp .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
PHP 7.3
# php -- BEGIN cPanel-generated handler, do not edit
# Set the "alt-php73" package as the default "PHP" programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-alt-php73___lsphp .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
PHP 7.2
# php -- BEGIN cPanel-generated handler, do not edit
# Set the "alt-php72" package as the default "PHP" programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-alt-php72___lsphp .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
PHP 7.1
# php -- BEGIN cPanel-generated handler, do not edit
# Set the "alt-php71" package as the default "PHP" programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-alt-php71___lsphp .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
PHP 7.0
# php -- BEGIN cPanel-generated handler, do not edit
# Set the "alt-php70" package as the default "PHP" programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-alt-php70___lsphp .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

Important Notes

PHP Modules Apply Across All Versions

Any PHP modules you’ve enabled in PHP Selector will apply to the per-directory PHP versions as well.

Only Affects That Directory

The PHP version you set only affects PHP files in that specific directory. Subdirectories will inherit this setting unless they have their own .htaccess file with different PHP settings.

Account-Wide PHP Version Still Matters

The PHP version set in PHP Selector is still your account’s “primary” version and affects:

  • Cron jobs
  • Command-line PHP scripts
  • Any directories without custom .htaccess settings

Frequently Asked Questions

Should I use this method or PHP Selector?
Use PHP Selector if you’re simply changing your website’s PHP version. Only use this per-directory method if you need different PHP versions in different folders (e.g., for testing or staging sites).

How do I know if I’m on LiteSpeed or Apache?
Check your hosting service details in the Ecenica Dashboard. Most newer accounts use LiteSpeed.

Can I set different PHP versions for multiple directories?
Yes. Each directory can have its own .htaccess file with its own PHP version setting.

What happens if I use the wrong code (Apache code on LiteSpeed)?
It won’t work correctly. Your site may display errors or fall back to the default PHP version. Make sure you use the correct code for your server type.

Will this affect my entire website?
No. It only affects PHP files in the directory where you place the .htaccess file (and its subdirectories, unless they have their own settings).

Can I remove this later?
Yes. Simply delete the PHP handler lines from your .htaccess file, and the directory will revert to using your account’s default PHP version.

I’m getting a 500 error after adding this code. What should I do?
You may have used the wrong server type’s code, or there may be a syntax error. Double-check you’re using the correct code for your server type. If the problem persists, remove the code and contact support.

Do I need to restart anything after changing this?
No. Changes to .htaccess take effect immediately.


Related Articles


Need Help?

If you’re unsure which server type you have or need assistance setting up per-directory PHP versions, contact Ecenica support and we’ll help you get it configured correctly.

Was this guide helpful?

Need help with this?

Open a ticket and link to this guide so our team can see what you have tried.

View support tickets

Power your business with Ecenica Hosting

Built for WordPress and serious websites. Fast, secure and supported by real people in the UK.

Ecenica hosting services represented by a connected red route across London