Creating Multiple Sites On Your Local Computer

Need another test site? Here's how to do it the "easy" way. [Hint: if you want several test sites, make a list right now. Read these instructions all the way through. Now you can do some of the steps in bulk to save some time.]

Why create extra sites? In addition to my having several sites running already, I had some ideas in the back of my head, not the least of which being a site where I could document everything I do (like this book). I also had some idea for other sites that I might put up in the future. So before you totally pooh-pooh the idea, give it a few minute's thought. And you can always change your mind later; it just might be a bit messier then.

At the very least, I would create a "working" site other than my "root" site. This makes it easier to start all over again if you get totally out of control later on.

This may look like a long process, but it's deceiving because I spell it out in detail. It is expanded and updated from the post "Running multiple sites on a local PC (localhost) from a single codebase, using Windows."

  • Open phpMyAdmin (using "other" in Web-Developer Controller)
  • start bulk loop 1

  • On the left, select the Drupal51 database. This is the one that was created by the package installation.
  • Click on "Operations"
  • Scroll down to "Copy Database to:"
  • Enter the new database name.
  • Verify that the radio buttons are clicked for:
  • Click on the Go button just below this area.
  • When the copy is complete, click on "SQL".
  • In the "Run SQL query/queries on database" box, enter:
    GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON databasename.* TO 'admin'@'localhost' IDENTIFIED BY 'superpw';
    FLUSH PRIVILEGES;

    admin is what I call my administrative role (this is the "super-user" name);
    superpw is the password for this user (I tend to use the same one for all my databases to make it easy).
    Hint: I created and saved this in c:/www/drupal/grant.txt so I could copy and paste.
  • Change databasename to the new database's name.
  • end bulk loop 1

  • Close phpMyAdmin.
  • Go to the www/Drupal/sites directory.
  • start bulk loop 2

  • Copy one of the site folders (e.g. default) and name it for your new site.
  • Open the directory, then open the settings.php file in Notepad.
  • Change the $base_db and $base_url lines. The $base_db line should have the name of the database you just created. The $base_url will be how you want to access the site.
  • Close the file.
  • If you are going to have site-specific modules or themes, go ahead and create directories in this site to hold them (named "modules" and "themes").

    end bulk loop 2

  • Navigate to the /www/Apache22/conf folder.
  • Locate and open the "httpd.conf" file (Hint: I always make a copy of things I'm about to change, just in case I mess up.)
  • I did notice that my version of Apache sets index.html ahead of index.php, so don't have an index.html in your directory.

  • Find the line that says "# Virtual hosts." Remove the "#" from the next line. This allows you to make all your other changes in a separate, and less dangerous file.
  • Save it.
  • Navigate to the /www/Apache22/conf/extra folder.
  • Open the httpd-vhosts.conf file.
  • At the bottom of the existing list, comment out ("#") the examples.
  • start bulk loop 3

  • At the bottom of the existing list, enter:
    <VirtualHost *:80>
        DocumentRoot /www/drupal/
        ServerName databasename
    </VirtualHost>
  • Change databasename to the new database's name.
  • end bulk loop 3

  • Close the file.
  • Navigate to the /windows/system32/drivers/etc folder.
  • Open the Hosts file with Notepad. Hint: these two steps can be done by using "other" in Web-Developer Controller.
  • start bulk loop 4

  • Add a line that says:
    127.0.0.1   databasename
  • Change databasename to the new database's name.
  • end bulk loop 4

  • Close the file.
  • Go back to Web-Developer Controller.
  • Click on Apache2 (top left).
  • Click the Stop Service button.
  • Wait for it to change to "stopped."
  • Click the Start Service button
  • Wait for it to say "running."

Go for it. You can now start the browser and enter http://databasename.


For more details on directories for multiple sites, see Setup of /sites directory for multi-site.

Comments

I feel that it is always

I feel that it is always better to have a facility to fearlessly test and experiment easily and faster with the new drupal and its features on your own computer and to try the new modules which you like to add before you add them on a live production site.For this you will need to setup drupal in a localhost .Its easy to setup one by installing wamp.

Multiple Test Sites in Fedora Linux

I worked my way through setting up multiple websites in Fedora in case anybody needs a pointer. sierrawayfarer@yahoo.com

Just found this...

While we're at it, here's a side note on how to avoid the most common mistake I see people running multi site installs for the first time make: Make sure that sites/default/ and sites/yournewsite.com/ each contain their own files directory. Then for each site, go to http://www.example.net/admin/settings/file-system and make sure that the "File system path" field indicates those directories (sites/default/files or sites/yournewsite.com/files) rather than just files. If you already have files in /files from your first site, you will have to move them to sites/default/files. This way, files for each site are separate. If you move or delete a site, you know which files belong to it and can move or delete those, too, without any special effort on your part. Also, it keeps the name spaces for the two sites' uploaded files separate.

While WE are at it... sigh.

The comment above is entirely cryptic ...how about a little more help for the noobs? I'm using Ubuntu v8.04 Hardy Heron, LAMP all set up, and Drupal v6. Can anyone expand on the comment above?

Skip it

As with many of us, I am back to recommending not using the sites/... solution.