Configure a Custom Domain Name on MAMP

MAMP custom domain name

In this post, we’ll look at how to configure a custom domain name on MAMP.

If you’re using MAMP (and do not want to invest in MAMP Pro) as your local development environment, you might find it useful to have a custom domain name set up on your machine during development. For example, using “yoursite.local” rather than “localhost”. This is especially useful when you are developing multiple projects on the same computer. You can associate each custom domain with a project directory under your MAMP’s “htdocs” directory. So, let’s see how we can set this up!

To set up a custom domain name on MAMP, you’ll need to make changes to your system’s hosts file and the Apache configuration. Here are the step-by-step instructions for configuring a custom domain name on MAMP:

Step 1: Choose a custom domain name

Decide on the custom domain name you want to use for your local development. For example, let’s assume you want to use “myproject.local”. It can also be “.yourname” or whatever other names you prefer to use.

A note : try to use a domain TLD that is not publicly used as top-level domain in the Domain Name System (DNS). “.local” is a good example. Refer to this page to see which domain TLDs are already in public and avoid using those TLDs.

Step 2: Edit the hosts file

  • Open the Terminal application on your Mac. You can find it in the Applications folder under Utilities. Or press command+spacebar and search for “terminal”
  • In the Terminal, enter the following command to open the hosts file in a text editor:
sudo nano /etc/hosts

You will be prompted to enter your administrator password. Enter the password as prompted.

  • The hosts file will open in the nano text editor. Scroll to the bottom of the file.
  • Add a new line at the bottom and enter the following:
127.0.0.1    myproject.local

Replace “myproject.local” with your chosen custom domain name.

  • Press “Control + X” to exit nano, then press “Y” to save the changes, and finally press Enter to confirm the file name.

Step 3: Edit the Apache configuration

  • In the Terminal, enter the following command to open the Apache configuration file in a text editor:
sudo nano /Applications/MAMP/conf/apache/httpd.conf

Again, you will be prompted to enter your administrator password.

  • The Apache configuration file will open in the nano text editor. Search for the section that starts with “<VirtualHost _default_:80>”.
  • Below that section, add the following code:
<VirtualHost *:80>
    DocumentRoot "/Applications/MAMP/htdocs/yourfoldername"
    ServerName myproject.local
</VirtualHost>

Replace “myproject.local” with your chosen domain name. The “DocumentRoot” folder will be the root for this custom domain.

  • Press “Control + X” to exit nano, then press “Y” to save the changes, and finally press Enter to confirm the file name.

Step 4: Restart MAMP servers

  • In the MAMP control panel, stop the Apache and MySQL servers by clicking the “Stop Servers” button.
  • Start the servers again by clicking the “Start Servers” button.

Step 5: Test the custom domain name

  • Open your web browser and enter your custom domain name (e.g., http://myproject.local or whatever you have set up in step 3).
  • If everything is set up correctly, you should see your MAMP project loaded using the custom domain.

Note: Make sure that any PHP files or projects you want to access using the custom domain name are placed in the “htdocs/yourfoldername” folder of your MAMP installation directory.

By following these steps, you can configure a custom domain name for your local PHP development using MAMP on macOS. You can repeat the steps with a different domain name and root folder if you are developing for multiple projects. This will keep your projects organized. Enjoy!