You Can Change the PHP Version of Websites Hosted With Hostgator to Version That Are Not Selectable

We were recently working on doing an upgrade of some very out-of-date software. As part of dealing with that, there was a need to change the PHP version being used on the website. We needed to change to a version that the web host of the website, HostGator, doesn’t appear to provide the ability to change to. The client thought that you had to go through HostGator’s support to change it to that version. It certainly looks like that, as they have a selector for customers that only allowed you to change to version to 8.1, 8.2, or 8.3:

Going through hosting support to address something that would be inconvenient at best. There is a simpler way to handle this. In root directory of the files for the website we were dealing with, was a .htaccess file. In that, there were the following lines:

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php56” package as the default “PHP” programming language.

  AddHandler application/x-httpd-ea-php56___lsphp .php .php5 .phtml

# php -- END cPanel-generated handler, do not edit

That code specifies what version of PHP is used on the website. The version of PHP being used on the website was 5.6. If you look closely at that, you can see at one point it says “php56”. Changing that changes the PHP version. So, for example, changing it “php74” would change the version of PHP being used on the website to 7.4.

While the first line says to not edit this, you can safely change the version there.

Another useful feature of changing the PHP version that way is that you can set the PHP version to a different version for different directories on the website. So we could in this change the version of a directory containing a test of the upgrade without impacting the running website.

Leave a Reply

Your email address will not be published.