My site’s php version isn’t the same as the hosting php version

This happens usually when websites are migrated from one hosting environment or infrastructure to a different one. Some hosting configurations let you manage the php version within each directory or website.

This is called out by an “addhandler” line of code. The php version is set or overridden by this command.

First we need to take a look at the .htaccess file in the active directory of the site.

The sample set I have is from the Media Temple transition from the GRID hosting to their new cPanel hosting. They moved everything over with some compatibility code to make sure things worked out of the box correctly. However this has cause confusion and frustration by clients who are trying to update plugins within WordPress and not being able to because of the php version.

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress


AddHandler application/x-httpd-alt-php73___lsphp .php
DirectoryIndex index.html INDEX.HTML Index.html index.shtml index.cgi index.pl index.php index.xhtml index.htm

You can see the first set of lines is the standard WordPress code that lets it function. Then we get to the compatibility code that is supposed to help… however… now it’s causing issues.

Right on the second line to the bottom we get the “addhandler” script. You can see it calls out ‘php73’ which means setting this folder to run php 7.3. This is our problem.

The correction is just by commenting out this line (or removing it, but I’m always nervous to modify client data so I use small modifications.)

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress


#AddHandler application/x-httpd-alt-php73___lsphp .php
DirectoryIndex index.html INDEX.HTML Index.html index.shtml index.cgi index.pl index.php index.xhtml index.htm

All we have to do is add a “#” to the beginning of the line and it turns green to let you know it’s a developer comment line instead of a computer command line.

Go ahead and clear your site cache, firewall cache, DNS cache and refresh your site… now the website should reflect the global php value instead of the addhandler override.