Drupal Development Environment on Mac OS X 10.6 - Multisite Capable

I've begun working a lot more with Drupal multisites, as doing so saves a lot of time in certain situations (usually, when you have a large group of sites that use the same kinds of Drupal modules, but need to have separate databases and front-end information.

One problem I've finally overcome is the use of actual domain host names for development (i.e. typing in dev.example.com instead of localhost to get to a site). This is important when doing multisite work, as it lets you use Drupal's built-in multisite capabilities without having to hack your way around using the http://localhost/ url.

Here's what I did to use dev.example.com to access a dev.example.com multisite in a Drupal installation using MAMP (the dev.example.com folder is located within Drupal's /sites/ folder):

  1. Edit MAMP/Apache's httpd.conf file - it's located at /Applications/MAMP/conf/apache/httpd.conf
    1. Put in the following at the end of the file:
        DocumentRoot /Applications/MAMP/htdocs
        ServerName dev.example.com
  2. Restart Apache (in MAMP, click stop servers, then start servers).
  3. Open up Terminal (in Applications > Utilities), and type in $ sudo nano /private/etc/hosts
    1. Type in your password if requested
  4. In the hosts file, add a new line after the line that reads         localhost:
    •         dev.example.com
  5. Save the file by pressing Control+O (this writes the file) and then Return when it says 'File Name to Write:', then press Control+X to exit nano.
  6. Now, flush Mac OS X's DNS cache by typing:
    • sudo dscacheutil -flushcache

Now, if you are behind a proxy server (i.e. if you have the Network settings in System Preferences set to use a proxy server for Web traffic), you will need to also add your dev.example.com entry to the 'Bypass proxies for these domains' field (localhost/ should already be present here).

Next time you visit http://dev.example.com/ in your web browser, Drupal should point you to the appropriate multisite folder on your local Mac!


And once you have this configured, you can keep adding to the hosts file, which makes testing systems like Domain Access, Aegir and Deploy possible.

For example, this is a snippet I use with MAMP to test Domain Access on localhost.

<br /> localhost<br /> example.com<br /> one.example.com<br /> two.example.com<br /> three.example.com<br /> four.example.com<br /> five.example.com<br /> six.example.com<br />

That's something I guess I forgot to add - it makes things quite convenient, when you're not working from localhost:8888 (MAMP's default address), or simply localhost.

Or, you can just get MAMP Pro for like CAD$67 and do the same with a much better interface (and having the chance to backup easily all that)

I manage about 150 local sites on my Mac and creating a new one usually takes me about 30 secs.
Open MAMP pro, create the site, point to the right folder, restart, close mamp.

Just a tip, make MAMP pro start servers independently from the GUI, that way you don't need to start mamp or have it running.

Hi i'm from Brazil.

I don't know why, but when i put $sudo nano/private/etc/hosts on terminal and push return button it returns the hosts, localhost but doesn't ask my password, so i can't change or insert the new hosts. Do you know why? Can you help me with this?



 FYI - make sure you have a space after "nano" - should be $sudo nano /private/etc/hosts