Master Changing PHP Version Using .htaccess in cPanel (No Server Access Needed)

Keeping your website running smoothly means staying updated — and that includes your PHP version. If you’re looking for a simple and flexible way to change the PHP version for a specific site or directory without affecting the entire server, you can easily do it through the `.htaccess` file right from your cPanel.  

.htaccess

In this guide, we’ll walk you through everything step-by-step — no guesswork needed!

What is the .htaccess File?

The `.htaccess` file (short for “hypertext access”) is a powerful configuration file used to control various server settings on a per-directory basis.  

It allows you to manage redirects, enable or disable features, improve security, and — in this case — set a custom PHP version for your site, without needing root access to the server.

> Note: Any changes made in the `.htaccess` file will only apply to the directory where the file is located and its subdirectories.

 Things to Check Before You Start

Before you proceed, make sure:

  • You know what PHP versions are available on your hosting server (this info is usually in your cPanel or can be confirmed with your hosting provider).
  • The PHP version is not already being forced by cPanel’s MultiPHP Manager or PHP Selector. Otherwise, the `.htaccess` method might not override it correctly.

If PHP is controlled by MultiPHP Manager or PHP Selector, you’ll need to adjust it from there instead.

How to Change PHP Version Using .htaccess in cPanel (Step-by-Step)

 1. Log in to your cPanel

  • Visit yourdomain.com/cpanel (or yourdomain.com:2083).
  • Enter your username and password provided by your hosting provider.

 2. Open File Manager

  • Inside cPanel, search for File Manager and open it.
  • This tool allows you to view and manage all the files and folders of your website.

 3. Navigate to Your Website’s Root Directory

  • Usually, your primary website’s files are located under public_html.
  • If you want to change the PHP version for a specific addon domain or subdomain, navigate to that domain’s folder instead.

 4. Show Hidden Files

  • In File Manager, click Settings (top-right corner).
  • Make sure to check the option “Show Hidden Files (dotfiles)” — this will make the `.htaccess` file visible.

->If you don’t see an `.htaccess` file, you can create one:  

->Click + File → name it `.htaccess` → Create.

 5. Edit the .htaccess File

  • Right-click the `.htaccess` file and select Edit.
  • Confirm the encoding if prompted.

Now, you’re ready to add the PHP version code!

 6. Add the PHP Version Handler

Depending on which PHP version you want, add one of the following blocks of code into your `.htaccess` file:

“`apache

# Example for PHP 8.1

<IfModule mime_module>

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

</IfModule>

“`

List of PHP Versions

Here’s the correct snippet for each version:

php-version

PHP Version Snippet
PHP 5.4 application/x-httpd-alt-php54
PHP 5.5 application/x-httpd-alt-php55
PHP 5.6 application/x-httpd-alt-php56
PHP 7.0 application/x-httpd-alt-php70
PHP 7.1 application/x-httpd-alt-php71
PHP 7.2 application/x-httpd-alt-php72
PHP 7.3 application/x-httpd-alt-php73
PHP 7.4 application/x-httpd-alt-php74
PHP 8.0 application/x-httpd-alt-php80
PHP 8.1 application/x-httpd-alt-php81
PHP 8.2 application/x-httpd-alt-php82
PHP 8.3 application/x-httpd-alt-php83

 

Simply adjust the version number according to the PHP version you need.

 7. Save Your Changes

– After adding the code snippet, save the `.htaccess` file.

– Close the editor.

How to Verify the PHP Version Change

To double-check that the PHP version was successfully updated:

  1. Create a new file (e.g., `info.php`) in your site’s root directory.
  2. Add this simple code:

“`php

<?php phpinfo(); ?>

“`

  1. Save it, and then visit `yourdomain.com/info.php` in your browser.

You’ll see a detailed PHP configuration page showing the current PHP version running for that directory.

  • Important:  

> Don’t forget to delete the `info.php` file afterward to avoid exposing sensitive server information publicly.

 Important Notes and Considerations

  • Directory Scope:  

  PHP changes via `.htaccess` only apply to the directory where the `.htaccess` file is located, not globally across the server.

  • Hosting Restrictions:  

  Some hosting providers may disable the ability to manually set PHP handlers via `.htaccess`. Always check with your host if you face issues.

  • Compatibility Checks:  

  After changing the PHP version, test your entire website (especially forms, plugins, custom scripts) to make sure everything works.  

  Some older plugins, CMS systems, or themes might not be compatible with newer PHP versions.

  • Regular Updates:  

  Keeping your PHP version updated is essential for:

  1. Security improvements
  2. Performance boosts
  3. Access to new features

  But always check compatibility before upgrading!

FAQs:

1. Can I change the PHP version for just one folder using .htaccess?

Yes! When you set a PHP version via the .htaccess file, the change applies only to the folder where the file is located and its subdirectories. This lets you run different PHP versions on different parts of your website.

2. What happens if my hosting provider doesn’t allow PHP changes through .htaccess?

If your hosting provider restricts PHP version changes via .htaccess, you’ll need to update the PHP version using cPanel’s MultiPHP Manager or PHP Selector instead. Always check your hosting settings or ask your provider for support.

3. How do I know which PHP versions are available on my server?

You can usually find the available PHP versions inside your cPanel under “Select PHP Version” or “MultiPHP Manager.” Alternatively, contact your hosting provider or check their documentation.

4. Will changing the PHP version via .htaccess affect my entire server?

No. Updating PHP through .htaccess only affects the directory where the .htaccess file is placed (and its subfolders). It will not impact other websites or directories on the same hosting account.

5. Is it safe to update my PHP version through .htaccess?

Yes, it’s generally safe. However, before making changes, always back up your website and test compatibility, especially if you’re running older themes, CMS platforms, or plugins that may not support newer PHP versions.

6. Why isn’t my new PHP version showing after updating .htaccess?

If the new PHP version isn’t taking effect, it might be overridden by cPanel’s MultiPHP Manager or PHP Selector settings. Check those settings first, or clear your server and browser cache.

7. What should I do if my site breaks after changing the PHP version?

If your site experiences errors after switching PHP versions, revert to the previous version in your .htaccess file or through cPanel. Then, troubleshoot plugins, themes, or custom code for compatibility issues.

8. How often should I update my PHP version?

You should update your PHP version whenever a newer stable version is available and your website is compatible. Staying updated improves security, speed, and overall performance.

Conclusion

Changing your PHP version using the `.htaccess` file gives you more fine-tuned control over your website environment — and it’s a fairly easy process once you know the steps.  

By staying on top of PHP updates, you ensure your site stays fast, secure, and ready for whatever’s next.

Keep exploring, keep improving, and as always — happy coding!

Share this article
Shareable URL
Prev Post

Step-by-Step Guide to Changing PHP Version via PHP Selector in cPanel

Next Post

How to Update Nameservers for a Domain (2025 Edition)

Leave a Reply

Your email address will not be published. Required fields are marked *

Read next