MAMP website setup FAQ: How do I configure MAMP and my Mac so I can develop a new PHP website? (Or, Can you share a Mac MAMP setup tutorial?)
Assuming you already have MAMP installed, creating a new MAMP website is pretty easy. I've gotten to the point where I can do it in about two minutes. You just have to configure your /etc/hosts file and your MAMP Apache configuration file. Here's how.
MAMP setup, Step 1: Adding host names to /etc/hosts
Let's assume you want to create a new web project named "drupal7", so you can access it in your browser with this URL:
http://drupal7:8888/
The first thing I do is edit my /etc/hosts file to add an entry with the name drupal7, like this:
127.0.0.1 drupal7 devdaily alaska
On that line I just added the entry for "drupal7", and the other entries on that line (codeme, devdaily, alaska) are other MAMP websites I'm developing on my Mac.
To edit the /etc/hosts file on a Mac OS X system you just edit that file like this:
sudo vi /etc/hosts
then insert the name you want to call your website project on the /etc/hosts line that has the 127.0.0.1 entry. As you can see from the example above, when you're developing multiple MAMP websites on one Mac like this, you just put all the entries on one line.
After putting that entry in your hosts file, you can ping the new hostname like this:
ping drupal7
Since I have my Mac firewall set up I just get a "request timeout" message, but that's good enough for me, I know it's trying to ping my Mac.
MAMP Setup, Step 2: Apache name based virtual host (NameVirtualHost) setup
The only other thing you have to do is add an Apache name based virtual host configuration entry into your MAMP Apache conf file, httpd.conf, which is located here:
/Applications/MAMP/conf/apache/httpd.conf
At the bottom of the file you just need to add some lines to tell Apache about this website. Here's what the DocumentRoot
entry looks like for my drupal7 project:
NameVirtualHost 127.0.0.1 <VirtualHost 127.0.0.1> ServerName drupal7 DocumentRoot /Applications/MAMP/htdocs/drupal7 <Directory /Applications/MAMP/htdocs/drupal7> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>
Once you have this entry in your MAMP Apache configuration file, just restart MAMP, and hit the following URL from your browser. If you already have your PHP files in your DocumentRoot directory everything should work fine:
http://drupal7:8888/
(The 8888 port shown is the default MAMP port. You can change that as desired, but it works for me.)
MAMP setup tutorial: Summary
I hope this MAMP setup tutorial has been helpful. As you can see, you just need to edit two files and you should be in business. MAMP is a terrific Mac PHP development tool.