How To Force PHP 5.3 For Your Enitre Hostgator Shared cPanel Account

Author:
phil
Created:
Monday, December 16th, 2013
Last Updated:
Tuesday, December 17th, 2013

Disclaimer: Accessing the information on this page means you agree to the Sites Terms of Service


I use Hostgator for my website hosting since about 2006 and for the most part, they've done a fantastic job of uptime and customer service. Since I started with them back in the earlier PHP days, the server I've been assigned to, hasn't been updated to force PHP 5.3 by default yet so I'm stuck at PHP 5.2 (or PHP 4 if I so choose) except... I don't want it to default to PHP 5.2.

cPanel has an option that is enabled by Hostgator, to choose between major versions of PHP, so between 4 and 5 and since the default for 5 is 5.2, I'm kinda limited. Now, the article linked above, does mention adding the code to any .htaccess file:

# Use PHP 5.3
AddType application/x-httpd-php53 .php

But it doesn't work. You have to change AddType with AddHandler But wait! Don't go off and start changing anything yet! The article says to do it for your "sites" .htaccess and sure, it will do it there, but there's a MUCH easier place to set it once and be done with it. Something that doesn't even seem to be documented by Hostgator...

Remember I mentioned that you can force between PHP 4 or 5? Well, the place to set this is at PHP Configuration in your cPanel. You'll find it down in your Software/Services section. When you open up the PHP Configuration, you'll see up there at the top some text that says: "The ".php" file extension will be processed by ..." and a dropdown box with "System Default | PHP 4 | PHP 5". Let's set this to PHP 5. What this does for us, is creates a .htaccess file in the root folder of our account. The one that is before your public_html folder.

Open the .htaccess file and it will look something like this:

# Use PHP5 as default
AddHandler application/x-httpd-php5 .php

Note: Your file might have some other stuff like:

<IfModule mod_suphp.c>^M
        suPHP_ConfigPath /home/youruser/php.ini^M
        <Files php.ini>^M
                order allow,deny^M
                deny from all^M
        </Files>^M
</IfModule>

Just ignore it. I have no idea what the ^M is for, but if yours has it, I'd say leave it.

Good, now let's make a small change and add a "3" so it looks like this (php5 -> php53):

# Use PHP53 as default
AddHandler application/x-httpd-php53 .php

That's it! If you have a PHP Info file setup to check your PHP version and details, it should immediately change from 5.2.x.x to 5.3.x.x and you're done. No more fiddling with manually adding the directive to each and every single new site! This will take care of EVERY php website within your public_html folder!

Post Comment

Comments

For webhosting, I would recommend people to read this post since Hostgator is not that great nowadays and they ended up the "Memorial Day celebration" promotion (50% off). So here are the Best Hostgator Alternatives

Keep in mind that "unlimited hosting" sometimes is not the best idea, there is no such thing as "unlimited disk space", but a "good enough" disk space to put a couple dozen of websites up, not hundreds, or even one very heavy site with thousands of high quality photos and stuff like that...

For Domain Names there are good and cheaper I would recommend to read Alternatives to GoDaddy.

I really want to thank you for this. You've turned a potentially very frustrating experience into a painless one. I needed to upgrade to php 5.3 and Hostgator's directions are lacking for someone who know zip+ about code. First they wanted me to change domain by domain, then they tell me to add

# Use PHP 5.3 AddType application/x-httpd-php53 .php

to the .htaccess file, but don't say where to add it. This is so much more simple and elegant a solution.

Thank you again