Drupal: An easy way to set up multiple sites on localhost

This works for a couple of subdomains/sites only. If you need to have a load of sites or other settings this is not for you. On the other hand this method needs no web server configuration.

  1. In your systems hosts file (Windows: In your favourite text editor open %SYSTEMROOT%\system32\drivers\etc\hosts and on Linux it’s /etc/hosts.
  2. Find the line defining 127.0.0.1, i.e. your local horst, erm localhost :) and append sitename1.localhost to the end of the line. do so for every site name you need.
  3. Go to your apaches/webservers documents folder holding your drupal installation. Say it’s htdocs/drupal than you need folder sites. There should be at least two folders called all and default. Copy default and name it sitename1.localhost, i.e. excactly the string you added to your hosts file (again you need to replace sitename1 by your site’s name but do include the dot!).
  4. In your web browser type sitename1.localhost/drupal to test if drupal shows up at all (meaning your OS resolves your “domain name” correctly) and if it shows your old content (meaning it works).

Now you have two options to actually set up your “new site”: Either edit the settings.php that should be in the new folder to use a diferent data base (that should be well-stocked with drupal data) or just install a fresh drupal site. You achieve the later by doing:

  1. Delete settings.php. That should leave you with a file named default.settings.php.
  2. Point your browser to sitename1.localhost/drupal/install.php and do everything like you did with the first install but use a diferent database (or the same but different database prefix).
  3. Done.

Resources

  • settings.php

Furthur reading

6 Comments

  1. ismayil said,

    Thursday, 26th Feb 2009 at 01:34

    For someone new to drupal/apache/php/etc, your instructions were super valuable and clear compared to dozens of other posts out there on similar topic. I followed the steps, it all works great, etc. So, many thanks.

    Regarding your comment “If you need to have a load of sites or other settings this is not for you,” could you explain why? Any explanation, general or detailed, would be super valuable to me (and others?) in better understanding how multi-site hosting works, I suspect. Following instructions is relative easy, groking the underlying logic is more elusive, but also more enduring.

    • sysblog said,

      Thursday, 26th Feb 2009 at 22:50

      ismayil, I appreciate acknowledgment!

      The simple reason why I wouldn’t recommend this method for more than a hand full of servers/ sites is that it would be a pain. You would at least want to hack a script that generates all your site names like devel1, devel2, devel3, etc.

      Cheers,
      sysblog.

  2. sysblog said,

    Saturday, 17th Jan 2009 at 14:06

    Thanks for sharing this information, ody!

  3. ody said,

    Friday, 16th Jan 2009 at 22:53

    also can do with ports; (tested on drupal 6.x)

    within apache config add listen port;
    open httpd.conf file
    find “listen 80″ –or whatever is there (listen x.x.x.x:80)
    add “listen 81″ –add below above
    add more? “listen 82″ –also new line
    save and close httpd.conf
    stop/start apache

    now under sites folder (defualt is drupal/sites)
    add new folder named “81.default” <–copy n past default folder and ren
    and another? "82.default" <–copy n past default folder and rename

    open browser; http://localhost:81/ -or- http://localhost:82/
    if app is on own server; simply change to servername; drupal is on my server named "mydrupalhost" from browser on another computer; http://mydrupalhost:81 –or– http://mydrupalhost:82

    -O

  4. The Snuffman said,

    Sunday, 28th Sep 2008 at 20:13

    I did a Drupal upgrade 2 weeks ago from 5.1 to 6.4 and consequently my whole site was broken and I have been unable to fix.

    Now I have finally cracked how to set up multiple sites on my localhost so I can properly test everything out.

    Your instructions above were so simple, why didn’t anyone else give me that info before,

    Thanks so much!
    The Snuffman

  5. james said,

    Wednesday, 10th Sep 2008 at 20:23

    nice post man.
    keep it up..


Post a Comment