Yes, here am I also trying to understand how setting up multiple sites work. Specifically, I want to start with
setting up a subdomain as an independent site. So, to test it out, I installed drupal in the /cms directory in my site, kudria.com, and tested it by creating the default account. Then, I created the directory voitures.kudria.com in the sites directory and copied the file settings.php into it and edited it. Now, how would I create the path to reach it? Since I am using godaddy to host my site, I would have to describe it how that subdomain works, or how a user would reach that directory once he types voitures.kudria.com. What should the path be to keep drupal happy?

voitures /cms/voitures.kudria.com
voitures /cms/sites/voitures.kudria.com

I guess I do not know if my question is drupal or godaddy related. =)

Comments

fen’s picture

You will have to add voitures.kudria.com as a CNAME or additional A record at your registrar. (I see that you've already done this.) You also have to tell Apache (or whatever you use as a web server) to use /cms as the document root for serving files from voitures.kudria.com; if using Apache, you can do this simply by adding ServerAlias voitures.kudria.com to the VirtualHost for kudria.com.

Note that in the sites/voitures.kudria.com/ directory you can also have a modules/ and themes/ sub-directories - useful when creating substantially different sites. I like to (on UNIX-based systems) separate the core Drupal from my sites completely, which makes upgrading Drupal easier. So I have a structure like:

drupal/
        4.7.10/
                sites @-> ../../sites
                sites.orig/
                ... (the rest of drupal's files)
        5.5/
                sites @-> ../../sites
                sites.orig/
                ... (the rest of drupal's files)
sites/
        foo.com/
                settings.php
                modules/
                themes/
        bar.com/
                settings.php
                modules/
                themes/
        baz.com/
                settings.php
                modules/
                themes/
foo.com @-> drupal/4.7.10
bar.com @-> drupal/4.7.10
baz.com @-> drupal/5.5

Keep the original sites directory untouched (rename it 'sites.orig') and make 'sites' a symbolic link to a top-level 'sites' directory where all the site-specific code goes.

Set Apache to serve foo.com from the top level "foo.com" and bar.com from the top level "bar.com". Minor Drupal upgrades can be done simply installing the new version under the drupal/ directory and changing a symlink (and running update.php).

If you want to get "fancy" you can even have a separate files/ directory for each site: add this to the bottom of the settings.php file:

$conf = array(
  'file_directory_path' => conf_path() .'/files',
);

Enjoy!

styro’s picture

but I don't know how hosters work, so I can't offer any specific pointers. I control my own Apache servers instead.

What you need to do is configure your hosting and DNS so that the URLs for both your intended sites end up getting served by the same index.php file in the Drupal root directory. Once you have happening, Drupal can then decide which site configuration to use. This could require a combination of virtual hosts, aliases etc.

Also it pays to get Drupal working properly first on your default site before trying to add additional sites.

--
Anton
New to Drupal? | Forum posting tips | Troubleshooting FAQ

dalek’s picture

What you mean is that if I placed drupal in /cms, I would point the voitures site to that same directory, index.php would somehow figure out that it has a subdomain in /cms/sites, right? How would it do that?

Incidentally, I am have no control of the web server itself nor I have command like access so I can ln things to a safe place. That is the price I have for using a web hosting company (godaddy incidentally). Still I think that there must be a way. After all, I can mess around with the CNAMEs, so half of the battle is won. =)

cog.rusty’s picture

Perhaps you can upload a small php file to create a symlink for you to do the job (If godaddy does not prevent this).

For more details.... I don't understand your directory structure yet.
Is Drupal installed in a /cms directory under your web document root? Or is it installed in your document root? Is /voitures another parallel directory under your web document root?

dalek’s picture

It is currently installed under /cms. I plan on moving it to the root when I get it to do my bidding.

senpai’s picture

I wanted two Drupal sites on one codebase installation. Actually, I wanted three, but I only got two working. What I'm warning you about is to be more that cautious when moving a working Drupal install from a server's subdirectory to its root directory. Sure, it may seem easy, and that's what i thought too, at first.

I had attempted, on my very first Drupalistic endeavor, to make two sites. I created a virtual host on my Apache server, and installed the main site in /mainSite/. The secondary, or testing and development site was installed in /developmentSite/.

I then made two different MySQL databases, just in case my fooling around cause major damage to the test site. I didn't want to wake up one morning with a screen full of PHP/MySQL errors!. Once I'd made the 'drupal' and 'drupalDev' databases, I configured each install's settings.php file appropriate to that install's $db_url (the database) and $base_url (the URL that the site gets accessed by.

My main site's URL was www.website.com, and the development site was a subdomain called development.website.com. Everything you've read so far is proper, safe, and sounds easy, right?

Here's where it got tricky. I installed the glorious gallery2 module on both sites. I think I actually had it configured to use the database that was appropriate to it's own site. I think. I turned on Drupal's URL rewrite for both domains, and I turned on gallery2's URL rewrite for both domains.

Knowing just enough about databases to blow up a small camel, I decided that everything was perfect. I'd make a few changes to the dev site, and then copy the relevant tables to the main site. I melted the dev site more than once while trying to get all these cool modules to play nicely with each other. If my dev site went belly-up, I'd just do a binary dump of the main site's entire database and write over the development site's database with it.

I then got the bright idea to move the main site's Drupal install (and gallery2, for that matter) to
the server's root directory. Now, I still had a working mainSite database, cause it was accessed using localhost, right? OK! Main site at / and development site at /development/.

Nope. Somewhere along the way, I missed something. The development Gallery2 was writing new users into the main, LIVE database. The live site's URL rewrite started failing when I'd change the .htaccess file in the /development/ directory? How? Why? Help!

I had been using two different codebases, two databases, and two directories. Maybe this isn't how it's supposed to work. Maybe I should have installed one codebase, and made 1, 2, or 3 different sites in Drupal's sites/ directory? Maybe. If I'd done that, however, where's the mechanism for an Apache Virtual Host to discover it's needed directory when a URL subdomain is called upon? Would development.website.com properly call the file in /development/sites/www.websitename.com/index.php ?

All I know is, I ended up re-creating my entire live site into the webserver's root directory, and I'll never move a Drupal install from directory to directory ever again. Build it where it lives.

--
Joel Farris
"...and that's the way it oughtta be!"

****
Joel "Senpai" Farris | certified to rock score

cog.rusty’s picture

I still don't get the full picture.

Are 'cms' and your *real* 'voitures' directory parallel or are they one inside the other?
Or are they the same thing?
Or there is no 'voitures' directory and the 'voitures.kudria.com' subdomain leads to your webroot?

To understand why I am asking: when the user types voitures.kudria.com this leads to some directory, ok? But you need to make it lead to /cms instead. To create a symlink which leads from 'here' to 'there' I must know where 'here' and 'there' is.

-----------

Here is something to try *if the 'voitures' and 'cms' directories are parallel*:

1. Delete or rename the 'voitures' directory.
2. Now, if you had shell access, you would go to your webroor directory and type:

ln -s cms voitures

This would create a symlink called 'voitures' (in the place of the old 'voitures' directory) which would lead to 'cms')

Without shell access, create a text file called, lets say, 'makesymlink.php' and put inside:

<?php
symlink("cms", "voitures");

Upload it to your webroot (not anywhere else because it contains relative paths), and run it with your browser (yoursite.com/makesymlink.php).

If godaddy permits you are done. Now your subdomain should lead to 'cms' and Drupal should figure out the right site to bring up.

-----

Edited to add: I just tried the above on a host, and the first time I got an "access denied" when running makesymlink.php. So, I made my webroot directory's permissions 777 for a moment (with FTP, with a right click in Filezilla) and it worked nicely.

dalek’s picture

First of all, I think that the idea of separating my content from the drupal code is very nice; I honestly did not even know I could do that. Shame on me! Since I will probably be blowing up the 4.7 install I have and replace it with 5.0, and I have not done much in the site that would hurt my feelings if I lose them, I have no problems starting everything from scratch. That said, right now I just want to see how to do the multiple site thingie. Then I can plan the side and do it right.

So, if we assume a stock install of 4.7 in the directory /cms, the two sites I have are in /cms/sites. Since I want to have a site called voitures.kudria.com, I first setup that subdomain to link to /cms because from what I read drupal would then figure out where to redirect the browser to. As I am using the godaddy host management interface, that would be done in the following screen:

http://kudria.com/projects/computer/kudria/images/subdomain.jpg

So, the idea is that voitures.kudria.com is pointing to the directory where drupal is installed. But, now how would drupal figure out where the directory containing the configuration for the site be? I was checking
settings.php and it seems to imply if I have a site that would be seen as http://www.kudria.com/cms/voitures, the path would be /cms/sites/www.kudria.com.cms.voitures. Is that accurate? Because I tried that and all I get is a message saying "Page not found."

cog.rusty’s picture

When a visitor's URL request lands into Drupal's directory (and automatically brings up Drupal's index.php) then Drupal compares that requested URL with the names of the subdirectories under /sites to find a match according to some rules.

You want the URL request to be not http://www.kudria.com/cms/voitures but http://voitures.kudria.com. If http://voitures.kudria.com really leads to the /cms directory, then it should be serviced using the settings under a /cms/sites/voitures.kudria.com directory.

If it does not work, check whether the "Page not found" error comes from Drupal (does it contain the druplicon?) or from the web server itself. If the latter, probably the subdomain doesn't send the URL request to Drupal (/cms).

dalek’s picture

I need to make a correction. What is shows is the default page, not a page not found error. The entry I created for voitures.kudria.com, it has its own database defined in its config file, so I would assume it to be independent from the default one. Also, the directory I created for the voitures site is /cms/sites/voitures.kudria.com.

cog.rusty’s picture

It is natural that http://www.kudria.com/cms/voitures gives you the /sites/default site, since there is no better match for this URL request.

But http://voitures.kudria.com should give you the /sites/voitures.kudria.com sub-site because that is the best match. Does this give you the default too?

dalek’s picture

It is pointing to the /sites/default site.

cog.rusty’s picture

Just to be sure, is "/cms" in lower case everywhere?

Another possible cause is that the user's http request is rewritten and not just forwarded. (You don't want the server to rewrite the user's requests.) For debugging, put the following in a text file and name it gethost.php

<?php print $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

Upload gethost.php to the /cms directory and run it with your browser using different requests to see if they all remain unchanged (this is what you want).

http://www.kudria.com/cms/gethost.php
http://www.kudria.com/cms/voitures/gethost.php
http://voitures.kudria.com/gethost.php

In all cases, the script should give you the same url that you requested.

If the request http://voitures.kudria.com/gethost.php gives you www.kudria.com/cms/gethost.php then there has been a server rewrite and Drupal won't know that you wanted voitures.kudria.com. In that case, the way in which the subdomain was created by your host was not right. But if the request remained unchanged then the problem is with your Drupal "/sites" setup.

dalek’s picture

/cms *should* be lower case. That said,

http://www.kudria.com/cms/gethost.php and http://voitures.kudria.com/gethost.php produced the right output (I added the string to the front so I knew it was the output I expected):

Path to this file: www.kudria.com/cms/gethost.php
Path to this file: voitures.kudria.com/gethost.php

Respectively. But http://www.kudria.com/cms/voitures/gethost.php resulted in a page not found. You can check them all since they are reachable right now. I am clueless why that happened, I did have its directory, voitures.kudria.com created inside /cms per instructions.

cog.rusty’s picture

Ok, http://www.kudria.com/cms/voitures/gethost.php gave you a "page not found" because there is no symlink or anything there and it was interpreted as:

http://www.kudria.com/cms/index.php?q=voitures/gethost.php

and of course Drupal didn't find such a page.

But this should not matter -- you don't want to use that long path anyway. What matters is that the other two work and the server setup is ok:

http://www.kudria.com/cms
http://voitures.kudria.com

Now, for Drupal to recognize these two sites you just need two settings directories containing the respective settings.php files with their database string.

/cms/sites/kudria.com.cms
/cms/sites/voitures.kudria.com

dalek’s picture

The way I have it setup is

/cms/sites/default
/cms/sites/voitures.kudria.com

since kudria.com is the default site. I would think that would do my bidding but I may be wrong. I also told each configuration file to look for its own database. So, worst case scenario (with voitures) would be IMHO that it would be annoyed with the database and bark at me. But instead it is going (defaulting?) to the default site. Is that an expected behaviour when it goes boink?

cog.rusty’s picture

Going to /sites/default is the default behavior if no good match with the user's request is found. This is documented.

Generally I avoid using 'default' and I always take care to have a matching directory name. I just leave 'default' alone -- less surprises and easier for updates.

But this is really unexpected when Drupal does receive the request for voitures.kudria.com intact and a /sites/voitures.kudria.com settings directory does exist. I can't explain it.

cog.rusty’s picture

I noticed another strange thing with your setup.

- www.kudria.com/cms/node works with clean urls
- voitures.kudria.com/node does not work with clean urls (it gives a server error), and you need to type voitures.kudria.com/?q=node.

If both sites accessed the same database, then the "clean URLs" setting should be the same for both but it is not... Was the other database an exact backup of the first one?

Maybe there is something in your .htaccess which confuses the second site? Is it unmodified?

I also noticed that you have been using an old Drupal version (4.7.2).