Home > Tutorials and Resources > Getting Started Guide for Local Test Server Setup > Installing MAMP and Setting Up Virtual Hosts

Installing MAMP for Mac and Setting Up Virtual Hosts

By B Lingafelter          testserver, workflow

This guide contains installation and configuration instructions for MAMP on Mac.

Installation and Configuration Instructions:

  1. Head to the MAMP website and download the current version of MAMP (3.5 as of Jan, 2016).
  2. To run the installer, double-click the MAMP_MAMP_Pro_3.5.pkg file.
  3. Accept all suggested defaults and click Agree when license agreement is displayed.
  4. Click the Install button, enter your Mac Administrator password, and click OK. Note: Administrator permission is also required to start/stop the Apache and MySQL servers.
  5. When installation is finished, open the MAMP Control Widget (Applications > MAMP folder).
    MAMP Widget
  6. Click Start Servers to start Apache and MySQL servers. You will be prompted to enter your Mac administrator's password, which is normal when starting or stopping servers.
  7. Click Stop Servers to stop Apache and MySQL servers.
  8. The default MAMP installation uses non-standard ports, because the Apache server that ships with Mac OS X is already configured to use port 80 (though it's not turned on by default). Because non-standard ports can be problematic, you should reset the Apache and MySQL Ports to standard default ports of 80 and 3306.
  9. In MAMP control panel, click Preferences.
  10. Select Ports tab (top) and click Set Web & MySQL ports to 80 & 3306. Set Nginx Port to 8080 (cannot be the same as Apache, which should be port 80).
    MAMP Ports
  11. Click OK.
  12. Select PHP tab and choose PHP 5.6.2 (if necessary)
    MAMP PHP Preferences
  13. Click OK.
  14. Before testing your installation, you should also check related System Preferences.
  15. Open System Preferences, and select Sharing (Internet & Wireless category). Note: Only on older versions. If you have a newer version like Yosemite and El Capitan, just skip this and File Sharing options in steps 16-19.
  16. Make sure that Web Sharing is not selected. Clear Web Sharing checkbox if marked.
    MAMP Sharing Preferences
  17. Check File Sharing and click the Options button.
  18. Make sure Share files and folders using FTP is selected. FTP is generally considered the standard for editing websites remotely, and Dreamweaver uses FTP (and its more secure sibling, SFTP) to manage sites.
  19. Click Done and close System Preferences.
  20. Now, you're ready to test your PHP installation.

Test PHP

  1. In MAMP Control Panel, click Start Servers and enter your Mac administrator's password.
  2. Click Open Start Page.
    MAMP Start Page
  3. When the start page opens in your default browser, click phpinfo link (or click phpinfo tab).
  4. Scroll down to the Core section and compare your values with those in Configuring PHP so you'll know what directives you need to change in your php.ini file.
  5. When ready to edit your php.ini file, be sure to Stop Servers (MAMP Control Panel). Refer to Modify php.ini for MAMP (Mac) for details on editing the php.ini file before you setup your virtual hosts.

Setup Virtual Hosts on MAMP

Creating a Virtual Host is a 2-step process:

  1. Add a new entry to your computer's hosts file that specifies the local domain name of each site on your local computer.
  2. Edit the Apache configuration file to register each Virtual Host in the web server (one for each site you want to test locally on your computer).

Create Virtual Host folders

  1. Open Finder and navigate to /Users/your_username/Sites/ Note: El Capitan and possibly Yosemite do not ship with a Sites directory. If you don't already have one, create a Sites directory in your home directory.
  2. Inside the Sites folder, create two subfolders: in234 and project.
  3. The in234 folder will hold tutorial files, and the project folder will hold your homework projects.

Edit hosts file

Be sure you have stopped your servers before proceeding.

IMPORTANT: To open the hidden hosts file in TextWrangler, choose File > Open. Set the Enable option to Everything and mark the hidden files checkbox in Open dialog box, then navigate to /private/etc/hosts. If you can't find it, choose File > Open File by Name. Type private/etc/hosts in search box, select the file found and click Open.

  1. Add the names of the your two virtual hosts as follows:
    MAMP hosts file
  2. Save and close the file. You will need to enter your administrator's password to confirm the changes.

Edit httpd.conf and httpd-vhosts.conf files

  1. Open the Applications/MAMP/conf/apache/httpd.conf file in TextWrangler.
  2. To turn on virtual hosts, enable the Include httpd-vhosts directive. Scroll to line 570 and delete the # (hash symbol) at beginning of this line to remove the comment:
    Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
  3. Save and close the file.
  4. In TextWrangler, open the Applications/MAMP/conf/apache/extra/httpd-vhosts.conf file.
  5. Scroll to line 19 and examine the following line:
    NameVirtualHost *:80
  6. Delete the # (hash symbol) at the beginning of the line if necessary.
  7. Create <VirtualHost> blocks for the localhost and your two virtual hosts as follows:
    MAMP httpd-vhosts.conf file
  8. Save and close the httpd-vhosts.conf file.

Test Virtual Hosts

  1. Open the MAMP Control Panel.
  2. Click Start Servers and enter your Mac administrator's password.
  3. Click Open start page. If your changes were made correctly, the MAMP start page will open in your default browser.
  4. To test one of the virtual hosts, type http://in234/site_check.php in address bar of a browser. If the resulting page returns the current time, the virtual host is working correctly.
  5. In the MAMP Control Panel, click Stop Servers and enter your Mac administrator's password.
  6. Click Quit to close the MAMP Control Panel.
  7. That's it! You're ready to start working on a project.

Resources:

Web Server and Related File Locations:

  • Document root: Macintosh HD:Applications:MAMP:htdocs
  • PHP Configuration (php.ini) file: /Applications/MAMP/bin/php/php5.4.4/conf/php.ini
  • Unlock and edit these three files:
    • hosts (hidden): Macintosh HD:private:etc:hosts
    • httpd.conf: Applications:MAMP:conf:apache:httpd.conf
    • httpd-vhosts.conf: Applications:MAMP:conf:apache:extra:httpd-vhosts.conf
  • Virtual host folders: /Users/your_username/Sites/your_site_folder/

Installation Resources:

Other Related Resources:

Troubleshooting MAMP PRO Database:

To access a database created with MAMP after your MAMP Pro trial expires:

  • Stop servers first!
  • Copy your MAMP PRO database files to the MAMP database folder. Make Backups! Just copy, don't move!
  • MAMP is using this mysql database: /Applications/MAMP/db/mysql
  • MAMP PRO 1.7.2 is using this database: /Library/Application Support/living-e/MAMP PRO/db/mysql or this database: /Library/Application Support/appsolute/MAMP PRO/db/mysql