Multisite in WAMP environment

jbc's picture
public
group: Multisite
jbc - Fri, 2007-07-27 13:04

I've been trying to get a multi-site Drupal 5.1, within a localhost (WAMP) environment. I want to have a common code base, but entirely separate databases AND when I upload to a live (WWW) environment I want my clients to connect to their domain constantly, ie, clientsdomain.net/node/xyz, NOT mydomain.net/sites/myclientsdomain.net/node/xyz

I've done the following:

  1. Install of core Drupal {primary}
  2. Put each site into sites/{secondary} folder -- settings.php to connecting to separate database
  3. Shared modules in sites/all/modules
  4. Site specific modules in sites/example.com/modules

However, surf to the {secondary} sites. (receiving "You Do Not Have Permission to Access..." error)

  1. Do you know if this is a limitation of a localhost environment? Will it magically work if I 'go live'?
  2. In a LAMP environment I don't usually bother with domain extensions and as below, trying them hasn't solved the issue.
  3. I surf to the primary site at http://localhost/primary/ — I've tried both http://localhost/secondary/ and even http://localhost/mainsite/secondary/ and even http://localhost/secondary.com (even though the .com is redundant in localhost / WAMP environment isn' it?)
  4. Any other reasons why this shouldn't be working? A problem with Apache?

Finally, will the client domain issue work as I wish in a multi-site install (surely the answer is yes!)??

thanks for any assist you can give.

shalom,
John


hosts file

mlsamuelson's picture
mlsamuelson - Tue, 2007-07-31 18:55

To setup multisites on localhost you'll need to edit the hosts file to add local domains pointing towards 127.0.0.1.

Open the "hosts" file it in Notepad, or your favorite editor. In XP, mine's at C:\WINDOWS\system32\drivers\etc

You'll see an entry like the following:

127.0.0.1       localhost

Add an entry for each of your local sites to create multiple local domains like so:

127.0.0.1       localhost
127.0.0.1       primary
127.0.0.1       secondary

Next, setup your settings.php files for these two sites in /sites/primary/ and /sites/secondary/

Then, make sure in your Apache httpd.conf, you've got something like the following:

<VirtualHost *:80>
    DocumentRoot "htdocs/YourRootDrupalDirectory/"
    ServerName primary
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "htdocs/YourRootDrupalDirectory/"
    ServerName secondary
</VirtualHost>

The ServerName will match your local domain, and the DocumentRoot will point to the directory where Drupal's index.php resides for both sites.

Make the updates, restart Apache. Then try to visit http://primary and http://secondary . If all goes well, you should see your sites.

mlsamuelson


apache/conf/httpd

jamescarvin's picture
jamescarvin - Thu, 2008-04-17 04:53

I meticulously followed all instructions from the downloading of web developer to the configuring, the copying of dbs on phpMyAdmin, to customizing settings.php for each newly created site, to adding 127.0.0.1 for each site name to the windows/system32/drivers/etc/host file and stop/starting apache.
I added VirtualHosts plus directory blocks for each site. I really don't see where I went wrong.

I was getting no permission granted at first, and then I put the path for VirtualHost to "/www/webapps/drupal/sites/remlm/" in apache/conf/httpd.conf

I've checked my syntax carefully, and reread every manual suggesting this method I can find on the forums/tutorials, several times each, plus dialoged for hours in IRC with support.

It doesn't seem to matter if I include a final slash or include quotes around the path to the site. At this point, I at least don't get permission denied. Apache seems to be pointing the right way. But I'm only seeing a list of files in the site's directory, including the settings.php file.

Aren't I supposed to see something like a template drupal site when I go to http://SITENAME ? Where did I go wrong?

James Carvin
Thank you for your help!


All VHosts point to the same index.php

Michael Hofmockel's picture
Michael Hofmockel - Thu, 2008-04-17 11:19

All your virtualhosts for every site run by Drupal should point to the same location: /www/webapps/drupal

Regards,
Michael Hofmockel


Thanks but then why doesn't that work?

jamescarvin's picture
jamescarvin - Thu, 2008-04-17 14:32

When on c:/www/apache22/conf/httpd.conf I change

DocumentRoot /www/webapps/drupal/sites/SITENAME
ServerName SITENAME

to

DocumentRoot /www/webapps/drupal
ServerName SITENAME

I go from seeing my directory for /www/webapps/drupal/sites/SITENAME - which at least is not an error

to

FOBIDDEN - you do not have permission to access this file, etc.

I think I'd rather see the directory list?

James Carvin
Thank you for your help!


all http requests to Drupal have to run through index.php

Michael Hofmockel's picture
Michael Hofmockel - Thu, 2008-04-17 19:56

Being able to index the sites directory is not good (not secure).

All http requests to Drupal have to run through index.php
Pointing your VirtualHost (directly or indirectly) to anything but index.php is incorrect.

Did you create your sites as subdirectories? I suspect you did.
If you created as subdirectories (example.com/site2), then you would get an error if you have not created a symbolic link. You can solve that error by creating a symbolic link. From line command (ln -s . site2). This is in the install instructions.

Did you create your sites as subdomains?
If you created as subdomains (site2.example.com), then you would also get an error if you have not registered the subdomain. Go register your subdomain with your Domain Name Server provider (you can do this from CPanel).


No two sets of install instructions made alike

jamescarvin's picture
jamescarvin - Sun, 2008-04-20 18:03

I set up the site the same way jbc did, who started this thread. That would not be "subdirectories" in the sense of me wanting http://maindomain.com/subdirectory - but they are sites that are located in drupal under /www/webapps/drupal/sites/SITENAMES - each is a subdirectory under sites.

If you are right, then if you would please clarify which file you are referring to that needs the ln -s added. I'll study up on symbolic links. But I think that is only for Linux. JBC and I (JDC) are using WAMP in this case. According to http://us2.php.net/symlink "Note: This function is not implemented on Windows platforms."

Anyhoo, after a long period of troubleshooting, which is spelled out at http://forums.devside.net/index.php?topic=1688.0 (as I viewed this largely as a Web Developer Suite issue) at this point I'm getting my sites to say "Welcome to your New Drupal Site". The solutions was to take all the VirtualHost and Directory block info off of the apache22/config/httpd.conf file and leaving only two VirtualHost blocks on the apache22/config/extra/httpd-vhosts.conf file, (which is listed as an active include on the httpd.conf file). The first of these blocks is says …

DocumentRoot /www/vhosts/localhost/
ServerName localhost
Include conf/extra/vhosts/localhost/*.conf

And the second says …

DocumentRoot /www/webapps/drupal/
ServerName sitenameprimary.com
ServerAlias sitename1.com sitename2.com sitename3.com

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

My troubleshooting had led me this far at the time I first submitted this post. Although I could see the Drupal welcome screen, I was getting a 500 error message when either attempting to log in or click on any of the links on the screen. The apache error log said …

[error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://sitename1.com/

I then started doing google searches and IRC and such and heard that maybe I needed to adjust my htaccess file. So I printed that out on the same forum thread at web developer suite community (linked above). At first I was of the opinion that since I never changed the .htaccess file to begin with, maybe that's not what's at issue...

But as it turns out, the forum Admin at Web Developer was very helpful, and pointed to one line that needed to be commented out.

RewriteBase /drupal just needed the "#" symbol in front of it to (comment it out).
# RewriteBase /drupal

This is how the file ships out in web developer. The line sends redirects in a never ending circle for any local domains in subdirectories of the base /drupal - and that would mean the site names directories in C:/www/webapps/drupal/sites/SITENAMES

James Carvin
Hoping to give back one day


setup settings and httpd.conf

freeburj - Thu, 2007-09-27 12:43

hello mlsamuelson,

Thanks for these instructions. As a newbie I am most grateful for this.

When you say to go ahead and 'setup your settings.php files for these two sites in /sites/primary/ and /sites/secondary/' what does 'setup' mean exactly? What modifications must be made to the settings file in order for it to work? For example, my Drupal installation is in www/Drupal/ and there is a folder /Drupal/sites/Default which only contains a settings.php file. I have copied this folder to represent my /primary and /secondary sites, but is this the correct way to go about it?

Also, when I update the httpd.conf file as you suggest, it just tells me I'm forbidden for any localhost address (//localhost, //primary, //secondary). I assume this must be a problem to do with the settings.php files?

Many Thanks,
John

I haven't looked into

mlsamuelson's picture
mlsamuelson - Thu, 2007-09-27 19:14

I haven't looked into setting up multisites with the fancy new Drupal 6 installer (though I imagine most of this is the same), but for earlier versions, "setup" meant going into the settings.php file and updating the $db_url variable to match your database access criteria. The comments in that file are very informative - recommended reading!

As for being forbidden, it sounds like more of a MySQL user access error to me. Make sure you've created your databases (these will be the same ones you're pointing to with the $db_url variable) and created a user to access them.

From the command line (assuming you have your MySQL bin directory in the path):

mysql -u username -p

(You have to login as a user with permissions to create databases and grant user privileges - I usually use root. You'll be prompted for a password.)

Once you've logged into MySQL:

create database yourdatabasename
grant all privileges on yourdatabasename.* to newusername@localhost identified by 'yourpassword';
flush privileges;

Then repeat the last three lines for the secondary database.

Now, if your $db_url is setup correctly in settings.php, you should be in business.

Checkout http://drupal.org/node/176025 if you need more help or perspective.


easiest just to run install as needed

Mike Stewart's picture
Mike Stewart - Thu, 2008-04-17 01:57

in both Dr5 & Dr6 you can just browse to the site, and if settings file is still vanilla, Drupal will initiate an install and do the work of editing settings.php for you - the only caveat is settings.php needs to be writeable by the webserver during setup (and will tell you so if its not setup).

And of course you still need to know the db user/pwd & db name.


hosts file read-only

Chris Charlton's picture
Chris Charlton - Thu, 2008-04-24 19:08

Note, your 'hosts' file permissions may be set to read-only. So, make sure you set your new 'hosts' file to read-only, or to change that permission if you plan to edit the file directly.


How I did it D6/WAMP

theletterm@drup... - Fri, 2009-01-30 17:28

Hey all.

Thanks for the help. Following instructions from this forum, here's how I set up multisite D6 in WAMP.

Install WAMP and Drupal per their installation instructions.
Keep in mind that in order to have more versatility, I did not install drupal in the WAMP root (c:\wamp\www), but instead in a drupal subfolder.
This mean my default drupal site is located @ http://localhost/drupal (c:/wamp/www/drupal).
Also, this is a single codebase, multi-DB installation.

Now, for the multisite setup:
1) Create databases and users as necessary for your multisite install.
2) Go to DRUPALROOT/sites in explorer and make a copy of the default directory, then rename it to whatever you want your site to be in the address bar.
ex. http://examplesite should be DRUPALROOT/sites/examplesite
3) Modify the settings.php to reflect the database and users for the new site.
4) Modify your httpd.conf file as follows:
Add in a virtualhosts block that looks similar to this:

<VirtualHost *:80>
    DocumentRoot "c:/DRUPALROOT/"
    ServerName SITENAME
</VirtualHost>

DRUPALROOT is the root of your drupal install (mine would be c:/wamp/www/drupal). DO NOT point this to the subdirectory you just created under the sites folder. Just point it to the Drupal root.
SITENAME is what you want to type into the address bar (same as the directory name you set above).

5) Modify your hosts file (c:\WINDOWS\system32\drivers\etc\hosts - open in notepad) as follows:
there should be a line that reads: 127.0.0.1 localhost.
Copy that line and paste it in a new line under the originial. On the new line change localhost to SITENAME.
It should look something like this:

127.0.0.1     localhost
127.0.0.1     examplesite

A few notes about hosts:
- You can add .com or whatever extension if you like. Just be SURE that SITENAME matches in #2 and #4 above.
- Your hosts-file may be read-only. Once you save changes open it again and make sure the changes saved. If you're running vista, you may have to run notepad as administrator before you open hosts in order to save changes

6) You should be all set to go now. Go to http://sitename/install.php and run the drupal installer. Unless you have an SMTP server installed and setup with WAMP, you will likely get an error about it not being able to send the admin email. Thats normal.

This really makes a nice environment for showing clients site mockups on a laptop or something like that.

Hope this helps!

M.

Best Match Yet...But Still Have a Small Problem

Summitt Dweller's picture
Summitt Dweller - Wed, 2009-05-06 00:26

Thanks M!

Your configuration and instructions are the best match to my localhost config yet...and it works at last!

But I do still have one mystery to solve before I'll rest easy. The only way I can access my sites is to reference them as http://site1/_drupal where _drupal is what I named my Drupal 6 installation folder. So, I have a hosts files with a line reading:

127.0.0.1 localhost
127.0.0.1 site1
127.0.0.1 site2

I've modified my httpd.conf file with sections:

DocumentRoot "c:/_wamp/www/"
ServerName site1

DocumentRoot "c:/_wamp/www/"
ServerName site2

And my D6 installation is in C:/_wamp/www/_drupal with my multi-site folders as C:/_wamp/www/_drupal/sites/site1 and C:/_wamp/www/_drupal/sites/site2.

Anybody got an idea why I'm having to tack the _drupal suffix onto http://site1 and http://site2 to make this work?

Mark


you almost had it, try this!

Michael Hofmockel's picture
Michael Hofmockel - Wed, 2009-05-13 20:15

httpd.conf should be:

DocumentRoot "c:/_wamp/www/_drupal"
ServerName site1

DocumentRoot "c:/_wamp/www/_drupal"
ServerName site2

Let us know how you make out?

Regards,
Michael Hofmockel
iMed Studios

Open Source || Open Access || Open Mind


Still No Go

Summitt Dweller's picture
Summitt Dweller - Thu, 2009-05-21 22:24

Thanks Michael.

Tried that modification to httpd.conf and restarted the server (a handful of times now) but I'm still seeing the same behavior as before... the _drupal suffix is required on my URL if I want to see my Drupal pages.

I did decipher that without the suffix what I was seeing before was a WampServer control panel complements of an index.php file left in the web root. I removed it and now when I leave the _drupal suffix off the URL I get an index page listing all the folders in the web root... including the _drupal folder. Not surprisingly, if I click on _drupal in that listing my target site pops up.

Mark