How to Change PHP Version via .htaccess in cPanel

How to Change PHP Version via .htaccess in cPanel

⚡ How to Change PHP Version via .htaccess in cPanel

Changing the PHP version is often required for application compatibility (e.g., WordPress, Laravel) or to boost performance with newer PHP releases.

You can do it in two ways:


✅ Method 1: Change PHP Version via cPanel Interface

This is the easiest method if you’re changing PHP for a single domain.

  1. Log in to cPanel.

  2. Find and click “Select PHP Version” (sometimes called MultiPHP Manager depending on your host).

  3. From the dropdown, select the desired PHP version.

  4. Click Apply or Save.

That’s it — cPanel updates the PHP version for that domain.


✅ Method 2: Change PHP Version via .htaccess

This is useful if you host multiple websites under one cPanel account and want each site to run a different PHP version.

  1. Log in to cPanel.

  2. Open File Manager.

  3. Go to your site’s root directory (usually public_html or the addon domain folder).

  4. Locate the .htaccess file. If it doesn’t exist, create one.

  5. Edit the file and add this code (for PHP 7.4 as example):

# Use PHP74 as default
AddHandler application/x-httpd-php74 .php
<IfModule mod_suphp.c> suPHP_ConfigPath /opt/php74/lib
</IfModule>

👉 Replace 74 with the version number you need (80 for PHP 8.0, 81 for PHP 8.1, etc.).

  1. Save the file and close the editor.

Now your site will run on the selected PHP version.


⚠️ Important Notes

  • The PHP handlers available (like application/x-httpd-php74) depend on your hosting provider’s setup. Some use MultiPHP Manager, others rely on .htaccess.

  • If your host runs CloudLinux with PHP Selector, the .htaccess line may look different, e.g.:

# Switch to PHP 8.1
alt_php81
  • After changing, always verify by uploading a phpinfo.php file:

<?php phpinfo(); ?>

Share

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0