mediatribe.net -- Drupal and Web Development

Notice: this post was last updated 5 years 38 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

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h3>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.