Skip to content
MAMP PRO Documentation

Virtual hosts

A virtual host is a configuration that tells a web server to serve different content depending on the domain name of the incoming request. A single Apache or Nginx instance can handle many virtual hosts simultaneously – each with its own domain, document root, PHP version, and SSL certificate.

This is the same technology that web hosting providers use to run thousands of websites on a single server. MAMP PRO brings it to your local Mac so that each of your projects gets its own isolated environment.

When you create a site in MAMP PRO, three things happen automatically:

  1. A virtual host entry is added to the Apache or Nginx configuration, mapping the site name (e.g., myproject.local) to a folder on your Mac.

  2. An entry is added to /etc/hosts so your Mac’s DNS resolver maps myproject.local to 127.0.0.1 (your own machine). This is why MAMP PRO occasionally asks for your administrator password – writing to /etc/hosts requires elevated privileges.

  3. An SSL certificate is generated for the domain so you can also serve the site over HTTPS.

After creating a new site, MAMP PRO automatically restarts the servers with the updated configuration. From that point on, your browser can reach the site at its own domain.

Before virtual hosts became the norm in local development, the typical approach was to place all projects inside a single document root and access them via subfolders:

http://localhost:8888/project-a/
http://localhost:8888/project-b/

This approach has several limitations:

Subfolder approachVirtual host approach
All projects share one PHP versionEach site can run a different PHP version
URLs don’t match productionURLs like myproject.local closely resemble production
No per-project SSLEach site can have its own SSL certificate
One document root for everythingEach site has its own isolated document root
CMS installations may break with path assumptionsCMS tools work correctly with their expected URL structure

The file /etc/hosts is a local DNS override table. Every entry you add there tells your Mac to resolve a domain name to a specific IP address without consulting an external DNS server.

MAMP PRO manages these entries automatically. When you create a site named myproject.local, MAMP PRO adds:

127.0.0.1 myproject.local

When you delete the site, the entry is removed. You can inspect the current state of /etc/hosts in any text editor (with administrator privileges) or in Terminal:

cat /etc/hosts

MAMP PRO generates virtual host configuration files automatically from its own settings. You should not edit these files directly – any manual changes are overwritten the next time MAMP PRO restarts the servers.

If you need to customize server behavior beyond what the MAMP PRO UI offers, use the template system accessible via File › Open Template. Templates let you modify the generated configuration in a way that survives server restarts.