How to Setup MAMP (MacOS, Apache, MySQL, PHP) Local Server on macOS 12 Monterey M1 Mac (2021)

Apple released its 2021 latest macOS 12 Monterey on October 25, 2021. It is the time of this year again that you might need to reconfigure your macOS if you are upgrading from macOS 11 Big Sur or older versions.

Or if you have a brand new Mac with macOS 12 Monterey, the below configuration steps should help you set up your local web server on the macOS platform.

On macOS 12 Monterey, Apache is built into the system. However, when you check the built-in Apache’s httpd.conf, you will notice a line says:

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

From macOS 12 Monterey, since there is no built-in PHP, if you want to set up a MAMP (macOS, Apache, MySQL, PHP) stack, I recommend using the Homebrew version of Apache as well as PHP.

Note:

Originally, this article is written targeted on macOS 12 Monterey. However, the same steps should be applied and worked on macOS 13 Ventura.

Disable macOS Built-in Apache

Since we will not be using the macOS 12 built-in version of Apache, if your built-in Apache is running, issue the following command to stop the Apache service.

Open Terminal and type:

sudo apachectl stop

Homebrew Installation

The first thing you need to do is install Homebrew to your macOS 12 Monterey system (if you have not installed Homebrew yet).

Check if you have Homebrew install or knowing the installed Homebrew version

Open Terminal and type brew -v

If returns something like:

Homebrew 3.3.0
Homebrew/homebrew-core (git revision 359f9f16171; last commit 2021-10-25)

This means you have Homebrew already installed. If you don’t see the above, follow the below steps to install the Homebrew in your system.

Go to https://brew.sh/

Copy the command of

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

Open Terminal and paste the above command.

Note: if you don’t have Command Line Tools for Xcode installed, the Homebrew installer will download and install the Command Line Tools for Xcode first then it will proceed to complete the installation of Homebrew to your system.

To learn more about Homebrew, check out How to use Homebrew on macOS 12 Monterey

Export the Homebrew Path

When you try to issue a brew command, you might get the below error.

zsh: command not found: brew

If you are getting the above error, you have to export the path by issuing the following commands.

Open the Terminal and type the below command and press Enter.

export PATH="/opt/homebrew/bin:$PATH"

then type the below command and press Enter.

echo 'export PATH="/opt/homebrew/bin:$PATH"' >> $HOME/.zshrc

Close the Terminal and re-open a new Terminal window.

Installing Apache via Homebrew

Once you have Homebrew installed and properly set the export, the next step is to install the Apache using Homebrew.

Open Terminal

Type brew install httpd

Configure the Homebrew version Apache (httpd.conf file)

Open Terminal

Type cd /opt/homebrew/etc/httpd/

Type sudo cp httpd.conf httpd.conf.bak and press enter (this step is optional if you want to keep the copy of the original config file.)

Type sudo nano httpd.conf

Enable the Modules and Configuration

You need to enable (uncomment the line) and modify/update the configuration in httpd.conf file.

To enable the modules, first, you need to find the modules that you want to enable.

Use control + w to bring up the search function, and look for the below modules and make sure to uncomment them. (remove the # in front of each line.)

LoadModule authn_core_module lib/httpd/modules/mod_authn_core.so
LoadModule authz_host_module lib/httpd/modules/mod_authz_host.so
LoadModule userdir_module lib/httpd/modules/mod_userdir.so
LoadModule include_module lib/httpd/modules/mod_include.so
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
Include /opt/homebrew/etc/httpd/extra/httpd-userdir.conf

Modify the DocumentRoot

Use control + w and search for DocumentRoot. Comment out (put # in front of each line of below.

DocumentRoot "/opt/homebrew/var/www"
<Directory "/opt/homebrew/var/www">

And add the below lines

DocumentRoot "/Users/USERNAME/Sites/"
<Directory "/Users/USERNAME/Sites/">

Note: USERNAME needs to be replaced with your username (e.g. developer)

Then you need to modify the options as below:

Options Indexes FollowSymLinks Multiviews
MultiviewsMatch Any
AllowOverride All

The final configuration of DocumentRoot should look like below:

#DocumentRoot "/opt/homebrew/var/www"
#<Directory "/opt/homebrew/var/www">

DocumentRoot "/Users/developer/Sites/"
<Directory "/Users/developer/Sites/">

    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks Multiviews
    MultiviewsMatch Any

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>ed

Modify the Listening Port

By default, it will listen to port 8080. If you want to listen to port 80, modify the Listen 8080 to Listen 80.

Use Control + w and search for Listen 8080 then replace with Listen 80

This is optional. You can keep using the default Listen 8080

Note: Your macOS Local Apache Server may be active on port 80. I would recommend to keep the HomeBrew version at port 8080.

Create Sites folder under your Username

Since we defined the DocumentRoot to be /Users/USERNAME/Sites. We need to create this “Sites” folder under the user “developer“.

Open Finder and navigate to the user’s folder.

Create New Folder and name it “Sites

Install PHP via Homebrew

Open Terminal

Type brew install PHP

Wait for the installation to complete.

Modify the httpd.conf to enable the PHP on Apache

Open Terminal

Type cd /opt/homebrew/etc/httpd/

Type sudo nano httpd.conf

Add the following lines.

LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

Use Control + w and search for DirectoryIndex, then add index.php

Create phpinfo.php file

phpinfo.php file will be used to check if the PHP is working or not.

Open Terminal

Type cd ~/Sites

Type sudo nano phpinfo.php

Once the nano application is opened, add the below line.

<?php phpinfo(); ?>

then press control + o to save then control + x to exit nano app.

Starting Apache server

Once the configuration of Apache and PHP are completed, let’s start up the Apache server.

Open Terminal

Type brew services restart httpd

To check if the Apache service running or not, type brew services list

You should see something like:

httpd started developer /Users/developer/Library/LaunchAgents/homebrew.mxcl.httpd.plist

If you see the “started” status, that means the Apache server is up and running.

Go to web browser and type localhost and press enter.

You should see a screen like below:

If you click the phpinfo.php, and if your PHP is working properly, you should see the PHP info page.

Install MySQL Server

Go to https://dev.mysql.com/downloads/mysql/

Select the ARM 64-bit DMG Archive and download the installer.

Once the installer is downloaded, double click and proceed as instructed.

Once the MySQL server is successfully installed, you should be able to see it in the System Preferences.

If you are looking for macOS 11 Big Sur version of how to setup the MAMP, please see Setting Up Your Local Web Server on macOS Big Sur 11.0.1 (2020)| MAMP Setup on mac | macOS, Apache, MySQL, PHP

Latest Posts

Feel free to share this post!

1 thought on “How to Setup MAMP (MacOS, Apache, MySQL, PHP) Local Server on macOS 12 Monterey M1 Mac (2021)”

  1. Pingback: Setting Up Your Local Web Server on macOS Big Sur 11.0.1 (2020)| MAMP Setup on mac | macOS, Apache, MySQL, PHP - Tech CookBook

Comments are closed.

Scroll to Top