How to Change the PHP Version for a Site or Folder With .htaccess

The old php5 handler lines no longer apply, but .htaccess can still pick the PHP version on many hosts. Here is the current cPanel format, safer panel options and how to verify the result.

On many shared hosts you can choose the PHP version for a site or a single folder by adding an AddHandler line to its .htaccess file. On cPanel servers it looks like AddHandler application/x-httpd-ea-php83 .php .php8 .phtml, which runs PHP 8.3. The safest way to get the exact line is to pick the version in your control panel, such as cPanel’s MultiPHP Manager or Hostinger’s PHP Configuration, which writes the correct handler for you. Afterwards, confirm the version with phpversion().

Originally published in April 2011 for switching between PHP 4 and PHP 5. Rewritten in December 2026 for current PHP versions and hosting panels.

What cPanel writes

When you select a version in MultiPHP Manager, cPanel adds a block like this to .htaccess:

# php -- BEGIN cPanel-generated handler, do not edit
# Set the "ea-php83" package as the default "PHP" programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php83 .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

To run a different version in one subfolder, for example an old app that isn’t ready for PHP 8, put a similar .htaccess in that folder with the version you need, such as ea-php74. Only versions installed on the server work. If the handler doesn’t exist, visitors may download your PHP source instead of seeing the page, so test right away.

Other hosts

The handler name depends on the server setup, so a line copied from one host often fails on another:

  • CloudLinux servers with the PHP Selector set the version per account in the panel, not in .htaccess.
  • Hostinger, SiteGround and others use their own panel settings.
  • On a VPS with PHP-FPM, the version is chosen in the virtual host or FPM pool configuration.

The old AddHandler application/x-httpd-php5 lines from the PHP 4 era don’t do anything useful on today’s servers. Remove them if you find them in an old .htaccess.

Check which version is running

Create a temporary file in the folder:

<?php
echo phpversion();

Open it in the browser, check the version, then delete the file. In WordPress, Tools, Site Health, Info, Server shows the PHP version.

The command-line PHP version can differ from the web version. Cron jobs and SSH commands may run an older PHP than your site, which causes errors that only appear in scheduled tasks. Call the specific binary in cron, such as /opt/cpanel/ea-php83/root/usr/bin/php, or check with php -v over SSH.

Before you switch

Upgrading PHP is one of the best things you can do for speed and security, but old code can break. Test on a staging copy first, turn on error logging, and look for deprecated functions. The official PHP 8.0 migration guide lists the removed and changed features you’re most likely to run into.

Common questions

Why do I get a 500 error after adding the AddHandler line?

The handler name doesn’t exist on your server. Remove the line and choose the version in your control panel instead.

Can I run two PHP versions on one site?

Yes, per folder, on hosts that support per-directory handlers. Each folder’s .htaccess sets its own version.

Which PHP version should I use?

Use the newest version your code supports that still gets security updates. Check php.net’s supported versions page for the current list.