mediatribe.net -- Drupal and Web Development

Notice: this post was last updated 5 years 50 weeks ago so it might be outdated. Please be cautious before implementing any of suggestions herein.

Drupal on a virtual host in MAMP on Mac OS X

When you install MAMP, localhost points to your htdocs folder. I install multiple sites in there, so that localhost/example, for example, is a Drupal site. The thing is, certain irritating things happen when Drupal is running in a subdirectory, so I would rather have my Drupal sites run on, for example, example.local. Here's how that's done:

== Before you start ==

Make a backup of your /etc/hosts file

Make a backup of your /Applications/MAMP/conf/apache/httpd.conf file, then add this to the end of the original:

NameVirtualHost *

ServerName localhost
DocumentRoot /Applications/MAMP/htdocs

== For each site ==

(1) add an entry to /etc/hosts

echo "127.0.0.1 example.local" >> /etc/hosts

(2) add an entry to the httpd.conf file

echo '' >> /Applications/MAMP/conf/apache/httpd.conf
echo '' >> /Applications/MAMP/conf/apache/httpd.conf
echo "ServerName example.local" >> /Applications/MAMP/conf/apache/httpd.conf
echo "DocumentRoot /Applications/MAMP/htdocs/example" >> /Applications/MAMP/conf/apache/httpd.conf
echo '' >> /Applications/MAMP/conf/apache/httpd.conf

(3) restart MAMP's apache

/Applications/MAMP/bin/apache2/bin/apachectl restart

Great tip! This was my method

Great tip! This was my method of brwiosng local web sites until I recently stumbled across a fairly new desktop server application called ServerPress, which handles the configuration of my hosts files for me via a step wizard.

As /etc/hosts is privileged,

As /etc/hosts is privileged, if (A) doesn't work for you right off the bat, use (B).

(A) echo "127.0.0.1 example.local" >> /etc/hosts"
(B) echo "127.0.0.1 example.local" | sudo tee -a /etc/hosts