As time goes on, upgrades become a necessity. Not only do they give access to new improvements, but they also help protect against known vulnerabilities.
I have upgraded PHP on a lot of Hostgator accounts this month as WordPress warns site administrators: “PHP Update Required WordPress has detected that your site is running an insecure version of PHP.”
Why is my PHP outdated?
Once upon a time, webhosts automatically updated PHP and MySQL on behalf of their customers. These upgrades were usually fine for up-to-date websites and those written with very simple code. But sometimes, these updates would break webpages or even worse, corrupt databases.
Now it is common to include tools so savvy customers can easily change PHP versions when they are ready. Unfortunately, this means many customers will suddenly find themselves several versions behind.
How do I upgrade PHP on Hostgator? (Fall 2020)
Reminder: Always make sure you have a fresh backup of your site before making major changes.
Log into cPanel and look under the Software section for “MultiPHP Manager”. This tool takes you to a page where you can select which domains and subdomains you want to control PHP for.
Choose the domains/subdomains you want to update, use the dropdown to select the correct PHP version, and click “Apply.”
Thoroughly check your website in case anything isn’t compatible with the new PHP version. If everything looks good but your site seems a little slow, try going up or down a PHP version.
MultiPHP Manager Broke My WordPress Site! What now?
Hostgator used to offer a cPanel tool called “PHP Selector” to change the PHP version in select folders. This tool added a few lines of code to the folder’s .htaccess file.
MultiPHP Manager controls PHP at a higher level. WordPress users switching from PHP Selector to MultiPHP Manger may notice error messages that include the line “Your PHP installation appears to be missing the MySQL extension which is required by WordPress.”
The fix is simple if you are comfortable editing .htaccess :
1. Open your favorite FTP program or cPanel’s file manager. Search for find the .htaccess .
You may have to adjust settings to show hidden files. cPanel’s File Manager has a settings button in the upper right hand corner.
Most sites have the affected .htaccess at either public_html or one level above. But I ran across two sites where the owners used PHP Selector on all of the sub-directories/folders.
2. Download or duplicate .htaccess and rename the copy with a timestamp in case it needs to be restored. (example: .htaccess_2020-08-28_14.50″)
3. Comment out the code that was added by PHP Selector
Sample Code Created by PHP Selector:
# Use PHP70 as default
AddHandler application/x-httpd-php70 .php
Commented Out Version:
# Use PHP70 as default
#AddHandler application/x-httpd-php70 .php
# suPHP_ConfigPath /opt/php70/lib
4. Save changes and view your website to make sure everything is working. If not, un-comment or restore the .htaccess files and switch your PHP version back to what it was (or “default” if you don’t see your old version listed.) Contact your webhost or other trusted IT person for help.
5. (optional) Delete extra .htaccess files or code. I totally delete .htaccess files that only contain commented out code. (I used my favorite FTP program to compare the file sizes in bytes to make sure I didn’t overlook anything.) For other files, I only deleted the lines that contained the above commented out code.
Check your site again to make sure nothing is broken! Feel free to leave comments and additional tips below.