Good content takes time and effort to come up with.

Please consider supporting us by just disabling your AD BLOCKER and reloading this page again.

Setup MAMP Virtual Hosts For Local PHP Development

20th April 2020 3 mins read
Share On     Share On WhatsApp     Share On LinkedIn

MAMP pro comes with loaded features, one of the main attraction is Hosts Management. Many of them who use LARAVEL or Symfony like frameworks need to start the server and restart for any small modifications in main configuration files.

This is kinda frustrating for developers as this itself becomes big headache. If your not using MAMP Pro and looking for to setup the MAMP then you are at the right place.


I hope that you might be having Laravel / Symfony kind of frameworks in /Applications/MAMP/htdocs folder. If still not then go ahead and install one now.

I am using PHP Laravel framework as an example. Please feel free to use any other framework as per your needs.

Step 1 - Check MAMP Ports & Configuration

Start MAMP server on top left corner go to

MAMP -> Preferences -> Ports

You will something like the following configuration

MAMP Ports Configuration

MAMP Ports Configuration

As you see in the above image I am having

Apache Port : 8888

Nginx Port : 8888

MYSQL Port : 8889

You can reset it to default ports by clicking on

Set Web & MYSQL ports to 80 & 3306

Then your ports will be as follows

Apache Port : 80

Nginx Port : 80

MYSQL Port : 3306

I am leaving for the default one. As in my docker file our company uses port 80 & 3306 as default ports for PHP & MYSQL respectively.

Step 2 - Laravel .env File Setup

Open your Laravel .env file make sure to make the following changes

I am taking stackcoder as laravel project and stackcoder.test for local development domain as an EXAMPLE :)

APP_URL - Observe 8888 port, And as you see http://stackcoder.test is the domain which will be pointing to your Laravel app in /Applications/MAMP/htdocs/stackcoder

DB_PORT - Observe 8889 port



Step 3 - httpd-vhosts.conf File To Add Your Virtual Hosts For APACHE

Run the following command.

sudo nano /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

This will open the httpd-vhosts.conf file where you need to add the following configuration.

The following code block is mandatory. Don't make any changes to it.

NameVirtualHost *:8888
<VirtualHost *:8888>
  DocumentRoot /Applications/MAMP/htdocs
  ServerName localhost

Below the above code add your project settings

<VirtualHost *:8888>
  DocumentRoot "/Applications/MAMP/htdocs/stackcoder/public/"
  ServerName stackcoder.test

DocumentRoot "/Applications/MAMP/htdocs/stackcoder/public/" this point to your Laravel project

ServerName stackcoder.test - You can add any domain name for testing

Your overall httpd-vhosts.conf will look something like the following

 NameVirtualHost *:8888
<VirtualHost *:8888>
  DocumentRoot /Applications/MAMP/htdocs
  ServerName localhost
<VirtualHost *:8888>
  DocumentRoot "/Applications/MAMP/htdocs/stackcoder/public/"
  ServerName stackcoder.test
<VirtualHost *:8888>
  DocumentRoot "/Applications/MAMP/htdocs/some_other_project/public/"
  ServerName otherproject.test

You can add as many projects you need.

Step 4 - Add stackcoder.test Virtual Host Name In /etc/hosts

Now you have added virtual hosts settings its time to setup stackcoder.test in the /etc/hosts file	localhost stackcoder.test otherproject.test someotherproject.test

Step 5 - Reload MAMP

Just go to MAMP and restart (stop & start servers) your MAMP sever

MAMP Main Configuration Page

MAMP Main Configuration Page

Step 6 - Test in browser

Now go to your browser and add the following in the url


Make sure to put 8888 port you have not set port 80 as default port


Once the development of the web application is complete you will be pushing to server. I have curated and written few articles on the same kindly read those.
How To Do Basic Server Security Setup For Ubuntu / Linux
How To Install Linux, NGINX, MYSQL, PHP (LEMP Stack) on Ubuntu
How To Install Linux, Apache, MYSQL, PHP (LAMP Stack) on Ubuntu

Author Image

Channaveer Hakari

I am a full-stack developer working at WifiDabba India Pvt Ltd. I started this blog so that I can share my knowledge and enhance my skills with constant learning.

Never stop learning. If you stop learning, you stop growing