In many web hosting environments, especially when using shared hosting or working with multiple applications, different PHP versions might be required across various parts of a single domain. Fortunately, if you’re using cPanel, you can How To Set Custom PHP Version Per Directory using .htaccess
.
This guide will show you how to set a specific PHP version for a folder inside your hosting account, while keeping a different version active for the rest of the domain. This is especially helpful for legacy PHP projects, or when testing compatibility with newer PHP releases.
Steps To How To Set Custom PHP Version Per Directory
1. Step 1: Log In to Your cPanel
Open your browser and log in to your cPanel account via:
2. Step 2: Open File Manager
Navigate to File Manager under the Files section.
3. Step 3: Create or Edit the .htaccess
File
If it already exists, right-click the file and select Edit.
If the folder doesn’t have a .htaccess
file, right-click and choose Create New File, then name it .htaccess
.

4. tep 4: Add PHP Version Handler
Add one of the following lines based on your required PHP version.

5. Verify the PHP Version
To verify the PHP version for that directory:
- Create a
phpinfo.php
file inside the same folder. - Add the following code:
phpCopyEdit<?php phpinfo(); ?>
- Open the file in your browser, e.g.,
yourdomain.com/old-script/phpinfo.php
- Look for the “PHP Version” field. It should reflect the version you applied in
.htaccess
.
Important Notes
- This method works per directory and overrides the default PHP version set via MultiPHP Manager.
- Only files within the directory (and its subdirectories) will use the custom version.
- If you’re not sure which handlers are available, contact your host’s support team. If you use Hostrago, our technical experts can help identify supported versions.
- Avoid using outdated versions (e.g., PHP 5.6) in live environments for security reasons.
Final Thoughts
Setting different PHP versions for individual directories is a powerful way to manage multi-version compatibility, especially when working with older applications or testing development environments. With just a few tweaks to the .htaccess
file, you can tailor your hosting environment to meet the needs of each application.
If you’re hosting with Hostrago, our cPanel plans fully support multiple PHP versions, allowing flexible development and deployment. Need help? Contact our support team or explore our Knowledge Base for more helpful tutorials.