Using Drupal's multisite feature, one can use a single codebase for multiple sites. This leaves a smaller footprint and makes your sites more maintainable since you only have to update one bunch of files.
This was already possible in versions prior to Drupal 7 by creating a configuration directory whose name was based on the site's hostname and pathname.
Although easy to setup this was sometimes cumbersome to maintain if you had different copies of your site running on different locations. During the creation of a site, one might typically maintain a development copy, an acceptation copy and a production copy. All these are on different locations. This would lead to creating several versions of the settings directory for one particular site.
In Drupal 7 a solution is provided for this particular problem. A new configuration file is available under the sites folder, called "example.sites.php". Using that file you can set up directory aliases. To see what those are, let's look at a particular example.
Suppose you are developing a site "http://www.example.com". You might then create a settings directory "sites/example.com". On your local machine, you're developing the site as "http://localhost/example.com". Normally, you would need to create a settings directory "sites/localhost.example.com". Now, in Drupal 7 you can tell Drupal to use the same directory, "sites/example.com" for the local copy by setting up a mapping or alias.
To do this, make a copy of "sites/example.sites.php" and name it "sites/sites.php". In there, set up the mapping using the sites array:
$sites['localhost/example.com'] = 'example.com';
This will instruct Drupal to use the example.com directory for the "http://localhost/example.com".
Comments
Thanks for this, saved me a bit of time. I was messing around with my vhost to try and achieve this when I came across your post. :)
thank you very much, now im updating all my sites in one hit :) workflow++ speed++
I fixed my problem...
I forgot to add the <?php tag at the begin of the file...
hi,
it's not work for me
I added the file sites.php on sites folder.
I added the content like you did.
$sites['localhost/ma-hh.co.il'] = 'ma-hh.co.il';
but when i go to:
localhost/ma-hh.co.il
i am redirected to
localhost/install.php
Do you know what is the problem?
thanks
Can someone explain in details the process to make multisite with sub dirs in drupal 7?
I answered my own question. In order to have different sites have different content and look different, I needed to create a database for each site being served. This also means needing to create new users for each site.
wow, you saved my day...tried the same with symlinks, but it didn't work out....although i don't know why...
I am a little unclear about one point. If I want to have multiple sites and have those sites look different and have different content, can those sites use a single database? I installed an additional site with a the same database, and the new site looks the same and has the same content. I expected it to look like a default Drupal site, with no content.
It's stunning just how hard it is to set up more than one site for development on a local host using WAMP or DAMP or MAMP.
Can anyone explain why it is that the whole of Drupal's CMS system seems to have this built in blind spot that forces developers to develop only one site?
I am a little more than bothered by the posts all over the internet about this that just say wait for Drupal 17 or that imply some fix that is machine and platform specific. People also keep regurgitating links back to Drupal.org to suggest some solution and there isn't one there. It's just a lot of try this or try that. I mean really, how many developers really are working only on one site at time???
I know it's all free and whatever but come on... surely among all the smart coders out there, one has to be able to make a clear and concise cross-platform tutorial about using a local host and developing more than one site at a time. Such a tutorial should definitely include how to take the site from a local host development on say MAMP or WAMP to a online hosted site.
Thank you for the post on multiple sites in Drupal.
I used the information in this post to help be configure full control of multiple sites in Drupal, sharing or isolating configurations at all levels (Project Level, Database, Drupal Version, Themes, etc).
Here are my notes on how I did the filesystem appears once setup.
Example directory structure to give full control of multiple sites in Drupal 7, DB, Document root, "sites" and "themes"
lrwxrwxrwx 1 root root ... {TOP_LEVEL}/html -> drupal-7.0-beta2 # DocumentRoot (html/) is controllable by a link too, allows me to install Drupal independent of changing Apache configs.
lrwxrwxrwx 1 root root ... {TOP_LEVEL}/drupal-7.0-beta2/sites -> ../sites # The installation links 'sites' to the parent. This totally isolates drupal installs from local configurations Allows for quicker Drupal installs, two steps: install, set the symbolic link.
drwxr-xr-x 5 root root ... {TOP_LEVEL}/sites/beta_oct2010.bikeshophub.com
drwxr-xr-x 5 root root ... {TOP_LEVEL}/sites/oct2010.bikeshophub.com
-rw-r--r-- 1 root root ... {TOP_LEVEL}/sites/sites.php
-rw-r--r-- 1 root root ... {TOP_LEVEL}/etc/apache2.conf # Apache Virtual setup and ServerAliases, shown below.
site A:
-rw-r--r-- 1 root root ... ./sites/sites.php
drwxr-xr-x 5 root root ... ./sites/beta_oct2010.bikeshophub.com
-rw-r--r-- 1 1080 1080 ... ./sites/beta_oct2010.bikeshophub.com/settings.php
drwxr-xrwx 4 root root ... ./sites/beta_oct2010.bikeshophub.com/files
Site B:
drwxr-xr-x 5 root root ... ./sites/oct2010.bikeshophub.com
-rw-r--r-- 1 1080 1080 ... ./sites/oct2010.bikeshophub.com/settings.php # you could consider linking this too if you like to share DB settings, etc.
drwxr-xrwx 4 root root ... ./sites/oct2010.bikeshophub.com/files
lrwxrwxrwx 1 root root ... html -> drupal-7.0-beta2
The apache settings, sharing the same virtual host and Document Root is optional.
ServerName oct2010.bikeshophub.com
ServerAlias beta_oct2010.bikeshophub.com
DocumentRoot /home/drupal/{TOPLEVEL}/html
...
To achieve this in D6 you can just use a symlink in your sites folder.
Only one question about the same in drupal 6. I'm trying to develop a Multisite drupal 6 installation.
I have 2 domains www.domain1.com and www.domain2.com
I've no problem to accessing from outside and from the server itself (editing hosts files and creating the sites/localhost.domain2.com/settings.php file). But how develop from the intranet (private network)?
if I put:
http://server_ip/ only the default site is shown. How to develop the second domain site from another station?
Thanks for your time and perhaps this newbie question...but google don't have any info about this...
Will drupal 7 support single codebase and site database without domain access module and table prefix?
Thanks for sharing this info. This will be very helpful. It took me a minute to grasp it's significance though.
You can follow the full discussion on why this feature was added in the issue queue.
You can still work your own way with with different configuration folders, include files, ... But most people try to have the exact same configuration for development, acceptation and production (maybe using virtual images).
I tend to agree with Christopher. If you have setup multi-stage deployment then your different sites likely require different database credentials. Also change/add different settings in settings.php they'll need to pass through quality assurance so they'll need to start out on your development site, get copied to your Q/A settings.php and then to the production settings.php.
Interesting feature,
Thanks Christopher
Christopher, I typically use a trick like this in my settings.php file to ensure different databases are used depending on whether I'm accessing the site on its testing server or its live server.
if ($_SERVER['HTTP_HOST'] === 'example.test') {
$db_url = 'mysqli://local_u:local_p@localhost/example';
}
else {
$db_url = 'mysqli://remote_u:remote_p@localhost/example';
}
Wouldn't your local dev and remote production sites then be pointing to the same database? Because settings.php is inside the sites folder? Don't you want the same code by and large but possibly some different modules restricted to one site or another, and definitely different settings.php files for each site?
Post new comment