How can I get PHP working again in the command line? [Mac Os]

-bash: php: command not found

image
DownloadNp
Last Updated: Jun 21st 2021

There is one of two things going on here, either you didn't install PHP, or PHP is installed and not currently in any of system aware paths. First I would try to find PHP and make sure it exists:

$ find / -name php -type f

You should see something like:

/path/to/your/php/bin/php

If PHP binary does exist, check your path:

$ echo $PATH

If it does not exist, recompile php.

If PHP exists on your system, make sure the path to the /bin/php file is included. You can edit your ~/.bash_profile and add the custom path like this:

PATH=$PATH:/path/to/your/php/bin/

....  

export PATH

Then save and reload the file to ensure your current session has access to new path changes:

$ source ~/.bash_profile

With any luck you can now do a php -v and see the version response.

 

-- Update --

Setting actual path:

$ vi ~/.bash_profile

...

# Add your custom php path

PATH=$PATH:/bitnami/mampstack-osx-x86/output/php/bin/

....  

export PATH

Save and close, then source it:

$ source ~/.bash_profile

And now you should be able to run PHP from cli:

$ php -v

Please Login to Comment