Site icon WP Smith

Hostgator SSH .bashrc and .bash_profile

So, recently, I need to run some php code from the command line and it kept throwing an error, one I recognized as related to PHP version, which I found extremely strange since all my sites are running either PHP 5.3.x or 5.4.x. This poses a problem because when you run php from the command line, regardless of what you have in your .htaccess file, Hostgator defaults to PHP 5.2.x. Don't believe me, try it.

Create this file (test.php) and place it at your root (~/).

<?php
echo 'Hello! ' . phpversion() . "\n";

Then type this in your SSH command line.

php test.php

It should output:

So I created a php alias, which worked well from the command line!

alias php='/opt/php53/bin/php'
alias wp='~/.wp-cli/bin/wp'
alias cdp='cd /home/tsmith/public_html'

However, when I ran a bash file, the error appeared again! Then upon dealing with it a bit more, I added the alias to .bashrc; however, .bashrc does not auto-load when a shell opens (just in case you didn't know!). And default .bash_profile does not exist, so I had to create .bash_profile. To do this from the command line type: nano .bash_profile into the command line.

nano .bash_profile

This will bring up a place to write into the file. Then add the following, which will autoload .bashrc, to the file.

[[ -s ~/.bashrc ]] && source ~/.bashrc

Enter Ctrl+X to exit and save. Type Y. Press Enter.

Then you will be back to the SSH command prompt. Now everything should work!