How change php version in command line?

5.7k Views Asked by At

I'm trying to install the composer on my website, but the server is running PHP 5.2, and the more I change my version of PHP by cpanel, it continues running PHP 5.2 on the command line.

When I run the php -v he passes me that the version of PHP is 5.2

Is there any way I can change the version of PHP in the command line? Or something like this.

3

There are 3 best solutions below

4
On

Without knowing the setup it is hard to advise you but this may work:

Usually when multiple PHP versions are present, a symlink is used to point /usr/bin/php to the version of PHP binary that should be active.

Firstly find out where the php executable is being picked from. This you can do by typing which php. This will tell you where php is being picked from. Now go to that folder and do ls -l and check if the php executable is a symlink. If it is a symlink you can delete the symlink and create a new one in its place that points to the correct PHP version binary.

ln -s '<path to php binary you want>' '<path returned by which php>'
0
On

1) phpbrew

2) echo "alias php='/usr/bin/< youre php version php7.1>'" >> ~/.bashrc && source ~/.bashrc

0
On

I had the same issue php 7 in cli, but the browser php is 5.6

I used

$ php5.6 <command>

This worked for me.