If you have multiple versions of PHP and you want to change PHP version in shell then run the following command:
1 |
whereis php |
This will give you a list of all PHP versions installed:
1 |
php: /usr/bin/php /etc/php.ini /etc/php.d /usr/lib64/php /usr/include/php /usr/share/php |
Find version that you need (i.e. /usr/bin/php71).
Then open .bashrc (or .bash_profile) and add the following line to the end of the file:
1 |
alias php='/usr/bin/php71' |
If you are using docker then you can do the following:
1 |
alias php='sudo docker container exec -it -w ${PWD} php74 php' |
Start new SSH session into your server and any “php” command will now use the php version specified in the ~/.bashrc (or ~/.bash_profile, ~/.zprofile).
Or you can refresh your session:
1 |
source ~/.bash_profile |
Verify your php version:
1 |
php -v |