I have been using php with mamp on mac for a year even with old versions of MacOS, since I installed MacOS Monterrey if I type php
on the terminal I get a message:zsh: command not found: php
Using older versions of MacOS I have never had this problem.
How can I solve the problem?
8
Answers
You probably need to fix it in the
.bashrc
file.Do this:
Open the terminal and run this command:
Then add this line in the
.bashrc
file:Save and exit (
ctrl + x
)I had the same issue after updating to Monterry. After some googling, I find out MacOS doesn’t include PHP. You need Homebrew to install PHP again.
brew install php
https://daily-dev-tips.com/posts/installing-php-on-your-mac/
I have same problem and this is the solution that I use for this.
install Xcode using your terminal
install homebrew using your terminal
when it finish the process you need to add the homebrew in your path and for this put this code
xxxxxxx write your user name
now you can check if homebrew is run correctly, use the next code.
you can see in the terminal the version that you have install in your pc
now is time for install php for this
finally, you can try see the version of php installed
When I update MacOS Monterey, PHP was remove.
I found this article it useful and solve this problem for me.
https://wpbeaches.com/updating-to-php-versions-7-4-and-8-on-macos-12-monterey
Add the PHP formulae
Choose the PHP version – this example uses 7.4
Link the PHP Version
Restart the Terminal
Homebrew users:
This can happen simply because your php version is not linked.
Goto /usr/local/Cellar, list out the content and see what versions of php you have installed. You should see directories and symlinks as so:
If the version you want is there, you can link it with
brew link [email protected]
.Then your bash should have php defined.
Installing php again will also work, because it will add the symlink in the install process; but you only likely actually need the symlink.
If you want the latest PHP release in macOS Monterey then follow these steps:
1:
brew tap shivammathur/php
2:
brew install shivammathur/php/[email protected]
3:
brew link --overwrite --force [email protected]
to check if its working, write this in the terminal:
php -v
if you get something along the lines of PHP 8.2.0-dev (cli) then its working
You have to edit the file .zshrc
and Then you update the path for your php
type on "?" search "php" … type enter, it will show you the line where php is. If not you have to add the path of your PHP.
You use Mamp, then it should on the root of mamp. set it on your .zshrc
This my .zshrc related to php :
Just using
brew install php
will install the latest php in mac.You can then enable php in Apache by adding the following to httpd.conf and restart Apache:
LoadModule php_module/usr/local/opt/php/lib/httpd/modules/libphp.so