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