Install PHP on macOS Monterey 12.4 and Set up Apache
PHP use to come pre-installed in earlier versions of macOS till macOS Big Sur. There was a line in the
1) The Apache HTTP Server
Apache 2.4 comes pre-packaged in macOS Monterey 12.4. Check the version to verify
If the version number is proper, start the server by running the command
The default It works! page is located inside
The "It works!" Page Location
2) Install Homebrew
Next, you need to install Homebrew. But to install Homebrew, you first need Git. If you have already installed Xcode in your system, you need not install Git. But if not, install it first.
After having Git in your system, go to Homebrew page and copy the command given for installation.
Run the command, and after Homebrew is installed, you can check its version.
3) Install PHP
You can choose to install a particular version of PHP, say, version 7.4. You can do so by typing the command
Now set the compilers to find PHP; do
Link the PHP version.
Now check the PHP version to confirm.
4) Changing the Work Directory
Get back to the login directory typing
Navigate to your home directory (it is named with your user name). In my case, it is
There, create a directory for your web projects, say
For easy access later, you can place this newly created
5) Modifying httpd.conf
If you have installed Apache via Homebrew, navigate to
Else, if you intend to use the pre-installed one, navigate to
Create a backup of the
We need to make some changes to the
Find the line
and change it to
Few lines below, you will find a litany of
Then few lines down, find the commented line
and uncomment it and change it to
Next, find the below two lines
and change them to
Lastly, add the below piece of code to the file.
Also, just so that an
6) Code Signing
Now if your
To avoid that, just append your code signing certificate name to the very line in the
If you do not have or do not know how to create a code signing certificate is macOS, go through the tutorial here.
7) Restart Apache
Now restart the server by running the command
Now all your web projects can go inside
Just for the purpose of testing, create an
Does PHP support macOS?
PHP is bundled with macOS since macOS X (10.0. 0) prior to macOS Monterey (12.0. 0). Compiling is similar to the Unix installation guide.
How do I upgrade PHP to 8.0 on Mac?
Upgrade to PHP 8.1 with Homebrew on Mac.
Normal upgrade. brew upgrade php..
Upgrade with shivammathur/homebrew-php. brew tap shivammathur/php brew install shivammathur/php/[email protected] ... .
Next steps. Check the current version by running php -v : php -v..
How do I upgrade PHP to 7.4 on Mac?
brew install [email protected]
brew link --force --overwrite [email protected]
brew services start [email protected]
export PATH="/usr/local/opt/[email protected]/bin:$PATH".
export PATH="/usr/local/opt/[email protected]/sbin:$PATH".
How do I upgrade PHP on Mac?
To update the PHP version, update the brew using the command brew update . Then, use the command brew upgrade php . It upgrades the current version to the latest version of PHP. Then, restart the webserver to see the changes.