Selecting PHP command line version on HostGator shared host

This took me a while to find, so I'm saving it somewhere I can find it again.

The easy way to select the PHP version used for web applications is to use the CPanel configuration tool. However, that doesn't work if you're using SSH and need PHP on the command line. Also, on HostGator, you can't create a symlink outside of your directory (such as to the global php).

You can find out what version you have with

$ php --version

If that's not the version you want, try a specific version like this (php55 is 5.5, etc):

$ /opt/php55/bin/php --version

If that works, add an alias to your .bashrc file.

$ nano ~/.bashrc

Add lines like the ones below and then Ctrl-X to close nano (be sure to hit 'y' to save changes when closing)

alias php='/opt/php55/bin/php'
alias composer='/opt/php55/bin/php ~/bin/composer'
export DRUSH_PHP='/opt/php55/bin/php'

Now, re-source the file so the command line gets the new aliases

$ . ~/.bashrc

Just as a sanity check, check the version again

$ php --version