zsh: command not found: php
Asked Answered
S

10

69

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?

Shonna answered 31/10, 2021 at 11:2 Comment(3)
Seems PHP is not installed or not in the path.Annabelleannabergite
My projects starts on localhost, but when I need the terminal to use for example 'php artisan serve' I get the message 'zsh: command not found: php'Shonna
same problem here too. Do anyone know how to resolve this?Barcroft
I
84

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/

Ichthyology answered 31/10, 2021 at 14:35 Comment(4)
I cannot install brew following documentation... Is there anything specific to do?Shonna
Did you enter this into your terminal? /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" brew.shIchthyology
Finally it's work, really thank you!Shonna
nobody mentioned that installing both homebrew and brew are quite slow tasks, and both will download and install a lot of big files! "This will take a while!!" :DTestify
L
121

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

brew tap shivammathur/php

Choose the PHP version – this example uses 7.4

brew install shivammathur/php/[email protected]

Link the PHP Version

brew link --overwrite --force [email protected]

Restart the Terminal

php -v
Lidda answered 22/11, 2021 at 13:30 Comment(1)
This should be the accepted answer.Doublequick
I
84

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/

Ichthyology answered 31/10, 2021 at 14:35 Comment(4)
I cannot install brew following documentation... Is there anything specific to do?Shonna
Did you enter this into your terminal? /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" brew.shIchthyology
Finally it's work, really thank you!Shonna
nobody mentioned that installing both homebrew and brew are quite slow tasks, and both will download and install a lot of big files! "This will take a while!!" :DTestify
V
16

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:

lrwxr-xr-x    1 kazajhodo  admin      7 May 22  2019 php72 -> [email protected]
lrwxr-xr-x    1 kazajhodo  admin      7 Feb 26  2020 php73 -> [email protected]
lrwxr-xr-x    1 kazajhodo  admin      7 Jun 12  2020 php74 -> [email protected]
lrwxr-xr-x    1 kazajhodo  admin      7 Jan 22  2021 php80 -> [email protected]
lrwxr-xr-x    1 kazajhodo  admin      7 Jan  4 11:58 php81 -> [email protected]
drwxr-xr-x    3 kazajhodo  staff     96 Jan  4 11:34 [email protected]
drwxr-xr-x    3 kazajhodo  staff     96 Aug  8 19:32 [email protected]
drwxr-xr-x    4 kazajhodo  staff    128 Jan  4 11:55 [email protected]
lrwxr-xr-x    1 kazajhodo  admin     18 Jan 22  2021 [email protected] -> /usr/local/bin/php
lrwxr-xr-x    1 kazajhodo  admin     18 Jan  4 11:58 [email protected] -> /usr/local/bin/php

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.

Vannesavanness answered 4/1, 2022 at 18:39 Comment(3)
This is the one. I downloaded [email protected] via brew without using a php formulae (see other responses). Using this I was able to locate and create a symlink. After that, 'php -v' works perfectly.Dissuasive
Works! Thank you. I used this command after downloading PHP view homebrewDuchess
I installed homebrew but don't have a /Celler folder in /usr/localUnhook
B
10

I have same problem and this is the solution that I use for this.

  1. install Xcode using your terminal

     xcode-select --install
    
  2. install homebrew using your terminal

     /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    

    when it finish the process you need to add the homebrew in your path and for this put this code

     echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/**xxxxxxx**/.zprofile
     eval "$(/opt/homebrew/bin/brew shellenv)"
    

    xxxxxxx write your user name

    now you can check if homebrew is run correctly, use the next code.

     brew --version 
    

    you can see in the terminal the version that you have install in your pc

  3. now is time for install php for this

     brew install php
    

    finally, you can try see the version of php installed

     php --version
    
Bile answered 5/11, 2021 at 1:48 Comment(0)
B
8

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

Borchers answered 16/2, 2022 at 18:52 Comment(1)
i got this error when I tried to run step 1. "Error: Failure while executing; git clone https://github.com/shivammathur/homebrew-php /usr/local/Homebrew/Library/Taps/shivammathur/homebrew-php --origin=origin --template= --config core.fsmonitor=false exited with 128. "Ema
M
3

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

Mongo answered 6/9, 2022 at 17:33 Comment(0)
A
2

You have to edit the file .zshrc

vim ~/.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 :

#export PATH="/usr/local/opt/[email protected]/bin:$PATH"
#export PATH="/usr/local/opt/[email protected]/sbin:$PATH"
#export PATH="/usr/local/sbin:$PATH"

export PATH="/usr/local/opt/[email protected]/bin:$PATH"
export PATH="/usr/local/opt/[email protected]/sbin:$PATH"
export PATH="/usr/local/sbin:$PATH"
Antre answered 11/5, 2022 at 23:22 Comment(0)
S
1

If you don’t have a brew on your Mac. First, install the brew using the terminal. Enter the code below and hit enter

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

After installed brew

Type

php -v

to check the PHP version if PHP is not enabled it shows

zsh command not found php

The next step for checking the PHP is to enter the below command in the terminal

Sudo vi /etc/apache2/httpd.conf

After running completely check the blow line is shown in the listed line

#PHP was deprecated in macOS 11 and removed from macOS 12

If you find this line is shown or you don’t have php then enter the command below in the terminal

brew install php

If you already have PHP installed or run the above command successfully, enter the command in the terminal below.

brew services start php

Then it shows successfully started php.

Next, check the PHP version by entering the command in the terminal.

php -v

It shows the PHP version installed on your Mac

reference link : https://medium.com/@nadine.fisch/add-php-to-apache-on-macos-12-e3bb43469195

Sergent answered 17/2 at 13:19 Comment(1)
Command brew link --overwrite php helped meAmalee
H
0

I see that everyone is suggesting to install PHP but my issue was that PHP wasn't linked. Here's how I fixed this issue:

brew unlink php && brew link php
Herisau answered 16/7 at 2:2 Comment(0)
S
-2

You probably need to fix it in the .bashrc file.

Do this:

Open the terminal and run this command:

nano ~/.bashrc 

Then add this line in the .bashrc file:

export PATH=$PATH:/usr/share/php/bin

Save and exit (ctrl + x)

Sinistrodextral answered 31/10, 2021 at 12:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.