How to use PHP Composer on HostGator

Zach picture Zach · Dec 15, 2012 · Viewed 17.7k times · Source

I recently decided to start a project in Zend Framework 2 and was having trouble getting it to run on a HostGator shared server.

By default, HostGator's shared servers run in PHP 5.2.2 and if you upload the ZF2 Skeleton Application, it will not run out of the box.

Also, if you happen to have SSH access to your HG Shared account (You usually have to request it), you won't be able to run .PHAR files because the CLI version of PHP is also 5.2.2.

Luckily, I got it to work... see below.

Answer

Zach picture Zach · Dec 15, 2012

First off, you can enable PHP 5.3 on HostGator on a directory level basis. Simply add the following line to the .htaccess file in your public directory:

AddType application/x-httpd-php53 .php reference link

Ba-Da-Bing! Now you can run your PHP 5.3 applications!

Oh, but wait! You have SSH access and want to use PHP Composer?
If you log in via SSH and try the following command: # php composer.phar install you will get the following error: Fatal error: Class 'Phar' not found in...

This is because HostGator's # php command runs in 5.2.2. To run in 5.3, you need to provide the full path to the 5.3 binary.

Here's the working command:
# /opt/php53/bin/php composer.phar install

I was so excited that I got this working that I figured I would share!