Cron Jobs & SSH Using PHP 5.3 on HostGator’s Shared Hosting

HostGator is one of the few hosts that enable its shared hosting accounts to use PHP 5.3. And enabling it is easy. Customers just need to add two directives to an .htaccess file, and Voila, their files are running on PHP 5.3! However, if you are trying to use PHP 5.3 for your cron jobs and secure shell (SSH), it can be a bit tricky. You will find that the .htaccess directives only control what version of PHP is used when the files are accessed via HTTP, and have no impact on cron jobs or SSH.

Use PHP 5.3 for Cron Jobs & SSH by Setting the Correct Path to PHP

To run a cron job or execute a PHP script using SSH, the default command which uses PHP 5.2, looks something like the example below.

php /home/user_name/public_html/folder/script.php

For PHP 5.3, you just need to change the path to PHP. See the revised example below.

/opt/php53/bin/php /home/user_name/public_html/folder/script.php

And that's all. In SSH, you can also verify the version of PHP with the following command. Currently, HostGator is running PHP 5.3.8.

/opt/php53/bin/php -v

Other Web Hosts

For other web hosts that allow you to optionally choose a non-default version of PHP, the process will be similar. You will need to find the correct path and use it to execute your scripts. Creating a
phpinfo()

file will yield some clues, but it might be easier to simply ask your hosting provider where the path is to the version of PHP that you want to use.

Tags: , , , , ,

2 Responses to “Cron Jobs & SSH Using PHP 5.3 on HostGator’s Shared Hosting”

  • Andrey Murashkin January 2, 2013 at 1:37 pm

    Big thanks to you!
    HG has very poor chat tech support, they tortured me for a hour telling me that I should add .htaccess with proper handler (sic!) to make it run with php command from CLI or CRON, next they convince that all is fine (hih whan I saw its 5.2!).

    I told that .htaccess is only about apache, but it doesn’t help them to solve the problem and tell me path to php 5.3.

    After a hour I googled this post and now I am so happy :) .
    Big thanks to you!

  • Muhammad Usman February 4, 2013 at 7:32 am

    Thanks, it saved my day. Hostgator should make PHP 5.3 default and 5.4 optional.

Trackbacks

Trackback URL:

Leave a Reply

Want us to work on your project?

Contact us today for a quote. Click here to submit details regarding your project.

If you are making a general inquiry, send an email to info@velvetblues.com

Go Daddy Deal of the Week: $2.95 .COM Domains! Offer expires 11/20/12!