Hello,

I'm trying to set up a multi-site installation, where individual sites have URLs like http://host/drupal/site1
So far, I've been unable to create more than 1 site.

The first thing I tried was installing the default site and then creating the other sites.

  • 2 MySQL databases, one for the default site and other for site1
  • Unpacked drupal to /opt/drupal-7.0
  • Edit settings.php for default and site1
  • Added the Directory entry in apache's .conf file. See below.
  • Changed rights for both sites
    • sudo chmod a+w sites/default/settings.php
    • sudo chmod a+w sites/default
  • Restarted Apache2
  • Called the install script http://host/drupal/install.php
  • Created a symlink for site1 (/opt/drupal-7.0/site1 points to /opt/drupal-7.0)
  • Called the install script on site1 http://host/drupal/site1/install.php... Fail, Drupal says it has been already installed. If I try to access http://host/drupal/site1/, I get the default site

Then I tried to call the install script of site1 before the default site, and then I got equivalent results (site1 becomes the only site I can access to).

I've also created a sites.php file when site1 was acting as the default one, but that did not help. Here is the content :

$sites['localhost/drupal/site1'] = 'site1';
$sites['localhost/drupal/default'] = 'default';

Here's the section of the VirtualHost:

Alias /drupal /opt/drupal-7.0
<Directory  /opt/drupal-7.0>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Location /drupal>
</Location>

Does anyone have a clue on what's going wrong or is missing?

Thanks in advance.

Comments

Hey gmirandaupc.

http://drupal.org/getting-started/6/install/multi-site

In step 1) I created one database for each drupal install, and then one table prefix for each domain that is working under that install. (I will have 3 installs of 2-4 sites each.)
2) create a directory for each site /sites/site1, /sites/site2 ...
4) Copy the file into each directory and rename it as suggested making sure it has write permission for user. (make sure that the directory does too 744?)
5) I use my hosts domain pointer and aim everything at the drupal directory.

... Seems to be working for me... On my 15th attempt.

PS The /sites/sites.php has no effect on the above and the /sites/default/default.settings.php never gets modified. and if you are going to be working on a site that you dont have the domain for yet you can follow the directions above and in the link to create a directory /sites/site4.com and then edit /sites/site.php with the lines :

$sites = array(
'site4.site1.com' => 'site4.com'
);

and when you point your browser to site4.site1.com it will install a new database table for the new site, and you can work on it until the domain arrives.

Hi Alajjana,

I already tried creating symlinks to /sites/site1, and file permissions seem to be ok.

The difference might be that my sites will be accessed via subfolders (i.e. www.me.com/site1).

How many times did you have to call install.php? Once for every site?

Regards,
Guillermo.

First ... I have no idea what a symlink is. LOL.

but from what i understand if the info below, if you want to access a www.example.com/mysite1 the directory would be sites/example.com/mysite1/ if you create that directory and place the settings.php inside with write permissions and browse www.example.com/mysite1 the install.php should start automatically.

I had a lot of issues until i created the directories and did an install thereby not getting the default/default.settings.php involved.

* 1. sites/www.drupal.org.mysite.test
* 2. sites/drupal.org.mysite.test
* 3. sites/org.mysite.test
*
* 4. sites/www.drupal.org.mysite
* 5. sites/drupal.org.mysite
* 6. sites/org.mysite
*
* 7. sites/www.drupal.org
* 8. sites/drupal.org
* 9. sites/org
*
* 10. sites/default

Ok so I have to say that the directory setup does not work. The sub.domain.com works fine. If you set it up doing domain.com/site all you will get is a Index. So I think the person who started this thread is correct to some degree.
I think what is really needed here is an Apache master. I personally fell it has something to do with the DirectoryIndex.
http://httpd.apache.org/docs/2.2/mod/mod_dir.html#directoryindex
I just have no Idea how to trouble shoot it, and from the lack of community help on this issue I would think most member dont.
I honestly believe that no one really has an idea how to set up a multi site with sub directories. Sub domains yes, but not sub directories. All the documentation I have read always goes back to the same thing....sub.domains.com

See the thing thats nice about sub directories is you dont need dns. all you need is 192.168.1.1/site and boom....that is if you could get it to work. But like I said....all you can get is a directory index. Its almost as you need to set something to run the php.

This could possibly help if someone could translate
http://www.drupalcoder.com/story/205-drupal-multisite-in-subfolders or
http://drupal.org/node/181288
but I cant seem to get it to work

Anyone know where I might be able to ask someone who know apache very well some questions to get the directory multi-site to work?

The following steps will set up a mutisite install of Drupal 7 on an Ubuntu server. The steps for another *nix distro should be quite similar. The sub sites being created here are not virtual hosts, but are actual sub sites, i.e. mainsite.com/subsite1, mainsite.com/subsite2, etc. Note that virtually everything here requires root access, so either login as root, or preface each command with 'sudo'.

1. Install Drupal 7 in the web root and verify that everything is functioning as it should, especially clean urls and SMTP mail functionality.
2. In the sites directory create a folder with a name that mirrors the web address of the sub site. For example, if the main site were accessible at mainsite.com and the sub site were to be accessed at mainsite.com/site1 then the folder would be created in the sites folder as mainsite.com.site1/.
3. Copy the default settings file at sites/default/default.settings.php to sites/mainsite.com.site1/settings.php.
4. In the sites folder there should be a file called example.sites.php. Copy this to sites.php, keeping it in the sites folder.
5. Edit sites.php and add the following to the end of the file:
$sites['mainsite.com/site1'] = 'mainsite.com.site1';
6. cd up to the web root and create a symbolic link as follows:
ln -s . site1 (this says "create a symbolic link so that when someone calls site1, look right here[.]")
7. In /etc/apache2/sites-enabled/ there should be a default .conf file - something like 000-default. I renamed this to default.conf, but renaming is not essential. But you must now edit this file to include the following lines:
<Directory /var/www/html/site1>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
8. Now restart Apache:
/etc/init.d/apache2 restart
9. Create an empty database for your new D7 site, along with a drupal user, granting permissions to the user for the database: SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES. (Note that the last two are not totally necessary, but as the documentation at http://drupal.org/documentation/install/create-database included these, for consistency's sake I also included them).
10. Flush the privileges: FLUSH PRIVILEGES;
11. Now run the install for the new site by opening the install.php script in a browser: http://mainsite.com/site1/install.php
12. If everything has been correctly configured the install process should now begin, ask you for the database name, user and location. Once this is finished, your new sub site should be ready to go.

One additional note: All of the sites will want to use the .htaccess file in the main D7 directory. For this reason, the RewriteBase directives in this .htaccess must be commented out:
# RewriteBase /drupal
# RewriteBase /
Otherwise clean urls will not work.

Thanks for the info. I though by doing what you posted in step 5 would have worked for me but I was wrong. However it was a step I think I was still missing.
When you say FLUSH PRIVILEGES; in step ten....I'm not sure what I'm suppose to do..Thats for the db correct. If that is true it should not effect the url at all.
Most of the configuration you explained I already had, except for step 5. However when I try to go to site.com/newsite I get a drupal page saying page Not found. I can however get site.com.newsite to work. Its almost as if the sites.php is having no effect.
One more question...you state in step 5 to do
$sites['mainsite.com/site1'] = 'mainsite.com.site1';
Should it be
$sites['mainsite.com.site1'] = 'mainsite.com/site1';
I'm not sure for me it matters as I still dont get the end result
The only thing I can get to work is site.com.newsite
Any ideas?

Got it!! I was creating the symbolic link wrong!
Thank you!!

I just read the code in the includes/bootstrap.inc(Line:377), the key with a slash(/) within the sites array will never be used, so the step 5 is useless.

Love is the only thing we can take when we leave!!!

In the Debian package for Drupal 7.4-1 there is no example.sites.php. I may end up figuring out how to create one but can anyone tell me where the file came from or whether/why it is no longer needed?

TIA

Paul Scott

Ok. I found the description of sites.php in bootstrap.inc.

Paul Scott

For me it is not possible to create a symlink, or to restart Apache, because my provider won't let me do that. I hope others can use this, I will wait for D8...

These instructions worked perfectly for me and were the best I've been able to find. Many thanks!

The name starts with zeros to make it first in the collating sequence. The directory sites-enabled is included by a wildcard reference, and processing is in alphabetic order. It establishes a default virtual host to be overriden by in later declarations. If there is no replacement declaration, Apache sends requests to this, the first declaration.

You probably don't want random requests and script attacks to probe your production sites.

Additionally, on Debian and descendants the vhost declarations should be in sites-available, not in sites-enabled. Use a2ensite and a2dissite to enable and disable sites.

John

There's a lot of various posts and possibilities here. Here's how I do it:

First of, this is single codebase / seperate database style under Drupal (7.7 core ATM):

1. Create site directory: sites/example.com (include all the necessary settings.php and whatever. From scratch, I usually just copy default and rename it and update the settings.php with the new DB's login info, but however you'd normally do it to set up a new site is fine -- i.e. copy the site/example.com directory from another server... you still probably need to make sure the DB config is correct, etc).

2. In sites/sites.php, add:

<?php
$sites
['example.com'] = 'example.com';
$sites['www.example.com'] = 'example.com';
$sites['stage.example.com'] = 'example.com';
$sites['local.example.com'] = 'example.com';
?>

In this way, you do NOT need to use symlinks (or junction if you're on older Windows) and you don't need to mess around with Apache (once you have Drupal working in the first place). If you use some sort of stack installer (Acquia for example), and you are creating your local.example.com site, just rename the site directory to example.com (or move the local DB config the installer puts in the settings.php to the existing settings.php in your example.com directory.

If you want to use separate codebases for the different sub-domains, it's just a matter of editing the sites.php file and creating another sites directory. Remember sites.php is used BEFORE the standard directory scanning, and any configuration found in sites.php will override whatever is discovered in the directory scan. Thame means if you have $sites['my.example.com'] = 'example.com'; in the sites.php file, but also have a sites/my.example.com set up, Drupal 7 will IGNORE the directory and use the sites.php configuration (so my.example.com will resolve to the same site as example.com).

This post seems a bit off-topic. Or is there a possibility to put the code base (the drupal php files) in a subdirectory, and not in the Apache document root?

this is totally not offtopic. it's the most simple guide on how to do this with drupal 7.

if you want a separate subdirectory sites like

simple create sites.php entries like

<?php
$sites
['host/drupal/site1'] = 'site1';
$sites['host/drupal/site2'] = 'site2';
$sites['host/drupal/site3'] = 'site3';
?>

check qhor.net/wiki/drupal:multisite for further details.

a blackhole is where drupal divided by zero

The above doesn't work. It just redirects to the main site.

Friendlydrupal.com - Drupal Video Tutorials

The first time I tried multisites was with D6 and I just couldn't get my head around it.
I do it on Linux, I don't have any idea how to do this on Windows. Something similar might be possible on Macs.

To find out where Apache was looking for stuff, I used strace. It's not installed by default, so one of these might be necessary:

aptitude install strace
yum -y install strace

Then this:
09:35 [john@ChessDev ~]$ sudo strace -f $(ps xa | awk '/apache|httpd/ {print " -p " $1}') -o /tmp/trace -e trace=open,access
Process 2822 attached - interrupt to quit
Process 9019 attached - interrupt to quit
Process 9020 attached - interrupt to quit
Process 9021 attached - interrupt to quit
Process 9022 attached - interrupt to quit
Process 9023 attached - interrupt to quit
attach: ptrace(PTRACE_ATTACH, ...): No such process

Load a page or two here, the C^ to break
^CProcess 2822 detached
Process 9019 detached
Process 9020 detached
Process 9021 detached
Process 9022 detached
Process 9023 detached
09:42 [john@ChessDev ~]$

Examine /tmp/trace for the results. egrep is your friend.

When I saw the order of directory accesses in my document root it all became clear.

John