mediatribe.net -- Drupal and Web Development

Notice: this post was last updated 29 weeks 2 days 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

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

Image CAPTCHA
Enter the characters shown in the image.