Install Composer on Bluehost

I ran into this problem a little while back when trying to install composer on Bluehost. While the PHP version used on Apache was a relatively modern v. 5.4, the command line was running php v. 5.2. Following the composer install procedure:

curl -sS https://getcomposer.org/installer | php

I kept getting the following error:

Status: 500 Internal Server Error
Content-type: text/html

It turns out, that Composer requires PHP 5.3.2+ to run, so how was I to access PHP 5.4 from the command line? It turns out that on Bluehost, you can access it directly at /ramdisk/php/54/php54-cli. So I did the following to make sure composer was available whenever I would ssh into the system:

  1. Created a directory off of my home directory called “common”

mkdir ~/common

  1. cd into the common directory

cd ~/common

  1. Install composer using php 5.4

curl -sS https://getcomposer.org/installer | /ramdisk/php/54/bin/php54-cli

  1. Set up an alias to composer using the php 5.4 command line in the .bashrc file

echo “alias composer=’/ramdisk/php/54/bin/php54-cli ~/common/composer.phar'” >> ~/.bashrc

  1. Run the following to make the changes take effect (thanks to the comments below for this):

source ~/.bashrc

And from there on out, I’ve got access to composer whenever I’m logged in. Keep in mind if you’re wanting to run it from a cron job, your alias won’t be available, so you’ll need to use the full path.