At some point, you might need to change the PHP version of your WordPress website, especially if you’re running on an old version.
So, in this tutorial, I’ll show you how to do that using .htaccess, which is a configuration file for servers that run on the Apache software.
Change the PHP version of your WordPress site using .htaccess
Before proceeding, back up your .htaccess file or your entire website, just to be extra safe!
Also, if you’re doing this to permanently upgrade the PHP version of your WordPress website, find out if your web host, theme, and plugins support a higher version of PHP, such as 7+.
Step 1 – Access your site’s files
Here’s how to access and edit your WordPress website’s files.
The .htaccess file should normally be in your WordPress website’s root folder – public_html
.
.htaccess in cPanel
Step 2 – Edit the .htaccess file
Open the .htaccess file for editing.
If you’re in cPanel, right-click on it and select Edit or Code Edit.
Editing .htaccess in cPanel
Step 3 – Add the code and save the file
I’ll give you several handlers to add, but you should stick to PHP 7+ [7.2 currently recommended] because it’s faster and more secure!
Add one of the below handlers right above the #BEGIN WordPress
line in your .htaccess file.
Change to PHP 7.3
AddHandler application/x-httpd-php73 .php
Change to PHP 7.2
AddHandler application/x-httpd-php72 .php
Change to PHP 7.1
AddHandler application/x-httpd-php71 .php
Change to PHP 7.0
AddHandler application/x-httpd-php70 .php
Change to PHP 5.6
AddHandler application/x-httpd-php56 .php
Change to PHP 5.5
AddHandler application/x-httpd-php55 .php
That’s a wrap
Hope you found the tutorial useful and managed to change the PHP version of your WordPress website using .htaccess!
Don’t forget to share the post to help out others!
You can quickly subscribe to my newsletter by using this link.
If you have any questions or thoughts, drop a comment or send a message via contact or Facebook page.
You can also hit the follow button on Twitter and subscribe to the YouTube channel.
My WordPress website or blog services are at your disposal!
Previously I worked through an issue where my host’s server was running PHP 7.4, but my site was not using it, by editing the .htaccess file. That worked great for a while, but then reverted back.
Upon closer examination I see the following in my .htaccess, which shows that the AddHandler is rewritten.
I’ve looked through my php.ini [which appears to show 7.4] and done some searches that reference needing to update Apache to get this fixed.
Can anyone provide some confirmation or alternatives to how to get WordPress to recognize the php version itself vs my manual edits of the .htaccess file?
Thanks
# 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.
AddHandler application/x-httpd-ea-php70 .php
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{Authorization}]
RewriteBase /site/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/index.php [L]
# END WordPress
The page I need help with: [log in to see the link]