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

  • 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

In your .bashrc modify your PATH:


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)


save and exit, then:

source ~/.bashrc

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

Further reading:



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



Hope this solution can help you ;-)

  • Thank You, It also fixed my composer issue.
    – fernandus
    Feb 18 '19 at 16:21

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.