C. Creating Multiple Sites On a Local Computer

Need another test site? Here's how to do it the "easy" way. [Hint: if creating multiple sites is desirable make a list of the desired sites before reading through these instructions completely. Some steps can be done in bulk to save 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." For more details on the "official" stance on the sites directories, read Setup of /sites directory for multi-site.

If you want to get deeper into creating multiple sites either locally or on your server, you can search the forums at drupal.org with the term "multi-site"; there is also a group devoted to this subject at http://groups.drupal.org/multisite. Within the Handbooks, there is a good section: Multi-site installation and set-up.

  • 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:
    • Structure and data
    • CREATE DATABASE before copying
    • Switch to copied database
  • 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 $db_url and $base_url lines. The $db_url 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.

Just found a quicker way to do this

WebWeaver64 - March 5, 2007 - 00:25

All of this is using the Web Developer Server Suite http://www.devside.net/ using their database password and installed to c://www/

1. Database: phpMyAdmin > Create a database for each local site you want to create.
2. Drupal: sites/default > Paste a copy of this folder for each site you want to create > edit the settings.php for each site.
3. Apache: Add a virtual host for each site in Apache22/conf/extra/httpd-vhosts.conf
4. Windows: Inform windows that each site is hosted locally in c:/windows/system32/drivers/etc/hosts
5. Reboot, or stop and restart Apache2
6. Open your browser and type in the http://siteaddress/install.php and follow the prompts. Do this for each site.

Database: phpMyAdmin > Create a database for each local site you want to create.
Open phpMyAdmin and type a name for your database (playsite) in the Create new database textbox, click Create (I left Collation, in the dropdown box). You should get a message that says your database is created. Click Home icon and add the next one.

Drupal: sites/default > Paste a copy of this folder for each site you want to create > edit the settings.php for each site.
The 1st copy I create is a folder called: copy from I then add to this folder a files, modules, themes, & tmp folder so that as I paste from this all the folders I need are also created.
Copy and paste to the drupal/sites/ one folder for each site you created a database for from your default (or copy from) folder rename each folders what you want the site address to be (mysite.tst). I like to have .tst at the end so I know I'm not online, and I don't accidentally go to a real site. Before you start to copy make sure the settings.php isn't marked as read only (right-click>Properties>Read-only need to be unchecked).

Open settings.php (using a text editor) from the Copy From or default folder and edit the lines necessary.
$db_url = 'mysql://username:password@localhost/databasename';
($db_url = 'mysql://root:rootwdp@localhost/playsite';)
$base_url = 'http://siteaddress';
($base_url = 'http://mysite.tst';)
Save As to the folder for the site you addressed in the previous step. Do this for each site you want to create. Use the file you have open, just changing what you need to in the file and Saving As to each of the folders. You don't have to reopen the copy from or default file.

Apache: Add a virtual host for each site in Apache22/conf/extra/httpd-vhosts.conf
(if you haven't already done so you need to remove the # from front the the line in httpd.conf in Appache22/conf/ that says # Include conf/extra/httpd-vhosts.conf)
Open in a text editor the file Appache/conf/extra/httpd-vhost.conf, add to the bottom:

<VirtualHost *:80>
DocumentRoot /www/drupal/
ServerName siteaddress (ServerName mysite.tst)
</VirtualHost>

Windows: Inform Windows that your site is hosted locally in c:/windows/system32/drivers/etc/hosts
Open in a text editor, the file hosts in c:/windows/system32/drivers/etc/ (You can do this from within the Web-Developer Controller Other>Windows HOSTS File) at the end of the file if it isn't there already add: 127.0.0.1 localhost then add the same for each site you are creating to host locally:
127.0.0.1 siteaddress (127.0.0.1 mysite.tst)

Reboot, or stop and restart Apache2
You can stop Apache 2 from within Web-Developer Controller. Click on Apache2 and click on Stop Service, when the status reads Stopped click on Start Service when the status reads Running you're good to go.

Open your browser and type in the http://siteaddress/install.php
Open your browser and in the address bar type http://siteaddress/install.php (http://mysite.tst/install.php), this begins the installation and populates your database with the tables. You'll get a message saying Congratulations, Drupal has been successfully installed. click on the link your new site. And you'll see a Welcome screen exactly the same as when you install on a "real" server. Click on the link create the first account. in Step 1, and you will be creating your Administrator account in Drupal. You will receive a warning about the mail function because unless you set up your local host to send email it can't, so make sure to save your just created User Name and Password somewhere safe because without it being able to send an email I'm not sure you could get into the administration any other way.

Your done.

403 Forbidden

planetology - April 17, 2008 - 20:30

I followed these instructions and I get a 403 forbidden error when I try to open the install.php page in my browser. I'm using Web Developer Controller v2.00 in Windows XP, and Drupal 5.7.

Jeff C

The Blog of Questions

Linux Version

DanEvans - March 30, 2007 - 05:27

Here's an initial stab at doing this on a Linux installation. Tested using Ubuntu 6.10, Apache 2, Drupal 5.1.
NOTE: Further digging suggests that http://drupal.org/node/53705 has a better (and probably "approved") approach. Read that carefully.

Assumptions:
1.Apache root is /var/www
2.Drupal initially installed at /var/www/drupal
3.Drupal database (in MySQL) is “drupal”

To create new site on same machine:
1.Create new copy of Drupal DB in MySQL (e.g., name it 'drupal2') by copying data & structure from the DB drupal
2.In /var/www, copy the drupal/ directory to new directory-- use same name as new DB (e.g., drupal2) (thus will have have /var/www/drupal and /var/www/drupal2)
3.In /var/www/drupal2/sites/default, edit the 'settings.php' to use the new DB name (drupal2)

That's it. Now you can navigate to http://server/drupal to access the original Drupal site and to http://server/drupal2 to access the new site.

Re: multisite needs multiple users

atulrd - July 10, 2007 - 19:22

Nancy,
I would like to say that the grants above should be executed for each databases.
i.e. If I create 3 database smdev,smtest and smprod
I should have 3 users as below
# Development SMDEV
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON SMDEV.* TO 'devadmin'@'localhost' IDENTIFIED BY 'admindev';
FLUSH PRIVILEGES;
# Test SMTEST
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON SMTEST.* TO 'testadmin'@'localhost' IDENTIFIED BY 'admintest';
FLUSH PRIVILEGES;
# Production SMPROD
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON SMPROD.* TO 'prodadmin'@'localhost' IDENTIFIED BY 'adminprod';
FLUSH PRIVILEGES;

And then - I refer each in settings.php

It took me couple of days to figure this out.
Your document says "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)."

But - I like your document - it got me started.

Regards
atul deshpande
atulrd@hotmail.com

"Loop"

NancyDru - July 10, 2007 - 21:34

"start bulk loop 1" and "end bulk loop 1" means to do each of those steps for each site/database.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

WAMP Configuration

cbarnett - August 9, 2007 - 12:24

I found a fairly odd, and dare I say erroneous, description of how to set up Apache, name-based virtual hosts in the devside.net forums. I added a reply there which simplifies it... I hope. The issue is the way 'webapps' are set up. It's a bit non-obvious, but it's very flexible, so I would recommend working with it, rather than stomping on it. Here's the link: http://forums.devside.net/index.php?topic=1539.0

BTW - By 'stomping on it' I mean installing Drupal in the main document root of your WAMP setup. This should work as well, but working with the WAMP setup gives you more choices.

Please note that I make no comment regarding the MySQL users and their passwords, or anything else. This is just about getting name-based virtual hosts working under the WAMP 'stack'. You have to do this before setting up virtual sites in Drupal - which is trivial, by the way, once you get virtual hosts working under Apache. If you're using the WAMP setup to run a Windows-based, publicly accessible set of virtual sites: 1. you're nuts, and 2. you'd better read up on security ;-P

"Open phpMyAdmin"

tchoakim - August 9, 2007 - 13:15

OK I really got stuck at this point. Every time I tried to go to MyPHPAdmin it would ask for a user and password. No clue as to what this should be as it wasn't involved in the install. Installed the Web-Developer Suite 4 times, twice on my desktop and and twice on my laptop. After messing around with all kinds of ini and config and php for 20+ hours I discovered that all I really had to do was use "root" as my user name and whatever password I had entered after performing the following directions from the Web-Developer manual.

Change the default MySQL user 'root' password

Open the command prompt and change to the C:\www\mysql5\bin directory...

mysqladmin -u root -prootwdp password new-password-here

Note that 'password' is a literal string -- do not substitute in anything.
Note that there is no space between '-p' and 'rootwdp'.

The key is that "root" is your user! Put that in with your password and you are in.

Note: This first sign in is when you want to create your "superuser" with all of the privileges.

Passionate about community, business, and the internet.

Default root password

kmull - November 9, 2007 - 03:53

tchoakim-

I had similar difficulties and wasted more time than I am comfortable admitting. To spare others from the misery that I put myself through, I would like to add to your comments.

Since it took me a little time to find it, here's the manual for Web-Developer: http://www.devside.net/download/wd-guide/

In addition, though the Security Measures section of the manual rightfully recommends changing the root password as soon as possible, it is not absolutely necessary. The default username and passsword to begin using phpMyAdmin as indicated in the manual are as follows:

Username: root
Password: rootwdp

A couple of "Gotchas"

aireworth - August 27, 2007 - 23:44

Firstly, thanks very much for the information here Nancy - it came in very handy. This page and the one on the "sites directory from multi site" were the most helpful (and eventually all I needed) when setting up Drupal for multisites.
However, I came across 2 things which greatly slowed me down - firstly, don't use upper case letters in the "sites" folder for the new site folder - e.g don't use "www.EXAMPLE.com" as a folder name. It seems Drupal doesn't equate www.EXAMPLE.com to www.example.com, and by the time the site name is passed to Drupal, all the upper case letters have been converted to lower case - by Apache or the browser or somewhere. I was trying to get multisite to work for (something like) AWVP.co.uk and had a folder in /sites/ called /AWVP.co.uk/, but I kept getting the default drupal site. Changing the folder name to awvp.co.uk made everything work properly.

Secondly, in the vhosts file, Apache uses the *first* virtual host entry as the default. So if it can't match anything else in the file it uses these settings. I had a first entry which said
"DocumentRoot /opt/lampp/drupal/" and as Drupal was not finding my sites I kept getting a "file not found" from the default install, even when trying to access localhost (which should have given me the default page from /lampp/). I got round this by adding a virtualhost entry which just said "DocumentRoot /opt/lampp/" at the top of the list.

Finally, although there are many ways to skin this particular cat, I found setting up the extra databases to be easiest by going to the phpmyadin home page, clicking on "privileges" and then on create new user. Give the user the new site name, and click on "Create Database with same name" granting full privileges. Then all you have to do is to copy the data and structure from the original Drupal database into the newly created one. It also means each database has its own user and password, although I don't know if there are any advantages or disadvantages to this.
Thanks again, Colin.

Good tips

NancyDru - August 27, 2007 - 23:49

I've also recently had problems with using upper case in the "files" directory. So I guess the operative word here is "DON'T." Keep everything lower case and you'll have fewer problems, even if you don't like the look.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

Case sensitivity

sleepingplanet.com - September 9, 2007 - 10:02

Hi,
just FYI, its apache that gets its knickers in a twist about the case.
So even if you aren't using drupal (i keep a couple of folders outside my drupal site for use by anon ftp etc.) You have to get the case right.
Keeping it all lower case is definitely a good idea. Very frustrating if you've spent a good few years programming and calling variables things like MyValue and HelloWorld.

Great handbook btw!

Vista Issues

mchenosky - November 13, 2007 - 04:13

I'm trying to set up multisite on windows Vista. When I followed exactly the "start bulk loop 3" step, I couldn't get it working. Then I searched on the web and figured to replace:

DocumentRoot "C:/www/webapps/drupal"
ServerName databasename

by:

DocumentRoot "C:/www/webapps/drupal"
ServerName databasename

Options All
AllowOverride All
order allow,deny
allow from all
AddType text/html .php .phps
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .phps

It seemed able to display the first page "Welcome to your new Drupal website!". But when I clicked any link (e.g. "Create new account"), I got an "Internet Server Error".
Any help will be welcome. I'll post any update if I get the "Internet Server Error" resolved.

Re: Vista Issues

mchenosky - November 14, 2007 - 06:19

The issue is in part b: basic configuration, I have enabled clean url. So for multi site setup, please skip that step. For detail, please read: http://drupal.org/node/186537. It solves my problem.

Poor Mans Version

saneangel - February 22, 2008 - 19:10

I had some success for my own needs and shared them at...

http://drupal.org/node/225455

Not for Newbies

mikeque - March 13, 2008 - 19:43

While this is important to mention to newbies, I think it is a little complex to dive into at the beginning of learning Drupal.

You have no idea what this put me through

jamescarvin - April 18, 2008 - 04:16

There are a couple of things peculiar to web developer that people will have to know. Since I spent the past thirty days installing and resinstalling it, and then finally getting these instructions right, only to have problems with VirtualHost and DirectoryBlock info not being set right, I wouldn't recommend this for a beginner - like I was.

But just in case you are new and you venture into setting up drupal through web developer, then please read through the thread I sarted on the web developer community site at http://forums.devside.net/index.php?topic=1688.0

I came into a problem that I know that some others have been having. And I finally solved it. Web Developer points php to vhosts rather than to www/webapps/drupal. This causes you to not get permission to access files or to get an html print out of your index.php file when you go to http://YOURSITE

Now, because I started trouble shooting and getting on forums and IRC at #drupal-support I got all sorts of opinions about how to fix things, which is what led me to put VirtualHost and Directory blocks into my httpd.conf file. People you talk to won't know right away that there is an include file pointing to vhosts unless they see your whole file, so if you take their advice you'll wind up with bunches of bad stuff.

Last comment - the Getting Started thread here talks about www/drupal - but web developer obviously puts it into www/webapps/drupal. Make sure you don't follow the instructions to the letter.

James

I was running into the same

MooMaster - April 18, 2008 - 16:33

I was running into the same 403 problem. I realized that, like much Open Source documentation, this is incomplete. Chances are that you got the 403 error because you are missing the proper permissions in your virtual host for directory access. It *really* should be the following:

# SexyTime virtual server used to test multi-site drupal setup
#
<VirtualHost *:8080>
        ServerName sexytime
  ServerAlias *.sexytime.*
  DocumentRoot "D:\www\webapps\drupal\sites\sexytime"
  <Directory "D:\www\webapps\drupal\sites\sexytime">
    Options Indexes FollowSymLinks
      Order allow,deny
Allow from all
  </Directory>
</VirtualHost>

Notice the Directory XML tag (Apache Directive). Without it, you are likely defaulting to root directory permissions, which deny all. Also, make sure your DocumentRoot is pointing to a valid path. Check your error logs in Apache/logs

Where xx is >= 2.2

Hope this helps
Moo Moo Moo

 
 

Drupal is a registered trademark of Dries Buytaert.