Hướng dẫn php command not found

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?

Hướng dẫn php command not found

leymannx

4,9095 gold badges40 silver badges45 bronze badges

asked Oct 31, 2021 at 11:02

3

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/

Link the PHP Version

brew link --overwrite --force 

Restart the Terminal

php -v

answered Nov 22, 2021 at 13:30

1

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 -> 
lrwxr-xr-x    1 kazajhodo  admin      7 Feb 26  2020 php73 -> 
lrwxr-xr-x    1 kazajhodo  admin      7 Jun 12  2020 php74 -> 
lrwxr-xr-x    1 kazajhodo  admin      7 Jan 22  2021 php80 -> 
lrwxr-xr-x    1 kazajhodo  admin      7 Jan  4 11:58 php81 -> 
drwxr-xr-x    3 kazajhodo  staff     96 Jan  4 11:34 
drwxr-xr-x    3 kazajhodo  staff     96 Aug  8 19:32 
drwxr-xr-x    4 kazajhodo  staff    128 Jan  4 11:55 
lrwxr-xr-x    1 kazajhodo  admin     18 Jan 22  2021  -> /usr/local/bin/php
lrwxr-xr-x    1 kazajhodo  admin     18 Jan  4 11:58  -> /usr/local/bin/php

If the version you want is there, you can link it with brew link .

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.

answered Jan 4 at 18:39

1

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
    

Dharman

27.7k21 gold badges75 silver badges126 bronze badges

answered Nov 5, 2021 at 1:48

If you want the latest PHP release in macOS Monterey then follow these steps:

1: brew tap shivammathur/php

2: brew install shivammathur/php/

3: brew link --overwrite --force

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

answered Feb 16 at 18:52

0

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//bin:$PATH"
#export PATH="/usr/local/opt//sbin:$PATH"
#export PATH="/usr/local/sbin:$PATH"

export PATH="/usr/local/opt//bin:$PATH"
export PATH="/usr/local/opt//sbin:$PATH"
export PATH="/usr/local/sbin:$PATH"

answered May 11 at 23:22

Kam DaneKam Dane

501 silver badge8 bronze badges

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

answered Sep 6 at 17:33

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)

answered Oct 31, 2021 at 12:03

Nabeel KhanNabeel Khan

3,4332 gold badges22 silver badges35 bronze badges

1

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