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

2
  • 1
    Is /usr/local/bin in your $PATH in .bashrc or .zshrc (if you use zsh)? It looks like just a problem of PATH configuration. You can check it with env $PATH Feb 10 '19 at 11:41
  • Is there a way to point with the same path.
    – fernandus
    Feb 10 '19 at 13:02
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 ;-)

1
  • Thank You, It also fixed my composer issue.
    – fernandus
    Feb 18 '19 at 16:21
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.