How do I change PHP version in shell?

Avatar
  • Answered
I have setup my account to use PHP v5.6 through cPanel. I then used phpinfo() to verify that I am using 5.6. However, when I login via SSH (command line/shell) and type "php -v", it shows I'm using PHP v5.4. I need to run some PHP through command line, but I need these commands to use 5.6, not 5.4. How do I update the shell to use 5.6?
Avatar
nvillescas
I found what I believe is a better solution. First, SSH into the server and run the following command: "whereis php". This will give you a list of all PHP versions installed. Find the one you want (i.e. /opt/php56/bin/php).

Next, find and open the file in your home directory called ".bashrc". Add the following line to the end of the document (without quotes): "alias php=/opt/php56/bin/php" (change the PHP path if you want a different version)

Save the file. SSH back into your server and any "php" commands you use will now use the version specified in the bashrc file. Run "php -v" to verify.
Avatar
Scott
Hello, Thank you for your question on php version via SSH. The phpinfo page uses the php version in your account or at the folder level you are checking. The SSH looks to the server default php version, that is why the versions are different. You can set the specific php.ini you want to use (thus changing the version) within the command line using these instructions. Kindest Regards, Scott M