0

I have installed php and in cmd on doing

sudo /usr/local/php7/bin/php -v

it shows the php version but on doing

php -v

its not showing getting us command not my phpinfo() also workd

how can I point to get php version on simply doing php -v

I am using centos7

fernandus
  • 143
  • 1
  • 9

2 Answers2

1

In your .bashrc modify your PATH:

PATH=$PATH:/usr/local/bin

or if you have to override the default version of PHP on Centos (this gives "priority" to PHP and other executables in /usr/local/bin)

PATH=/usr/local/bin:$PATH 

save and exit, then:

source ~/.bashrc

It should work and php -v doesn't require you to specify the full path

Further reading:

https://www.tecmint.com/set-path-variable-linux-permanently/

https://help.dreamhost.com/hc/en-us/articles/214202148-How-do-I-change-the-PHP-version-my-shell-uses-

I assume you are beginning your geeky adventures with Linux, if the answer is yes, take also a look at:

https://vegibit.com/vi-editor-tutorial-for-beginners/

https://www.howtogeek.com/howto/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor/

Hope this solution can help you ;-)

fromthestone
  • 347
  • 4
  • 17
0

With my local ubuntu 18.04 I changed from PHP 7.1 to 7.2

  vi ~/.bashrc
  echo "PATH=/usr/bin/php7.2:\$PATH" >> ~/.bashrc
  echo "alias php='/usr/bin/php7.2'" >> ~/.bashrc
  source ~/.bashrc

  sudo a2dismod php7.1
  sudo a2enmod php7.2
  sudo update-alternatives --set php /usr/bin/php7.2
  sudo service apache2 restart
fernandus
  • 143
  • 1
  • 9