By Mahmoud Mostafa | Sat, March 05 2011
After some hours of searching I discovered that there is a lack of Drupal 7 multisite tutorials there was only one article that talks about the new sites.php feature - (there are some more now), but when it comes to simple guides, there's hardly any thing like that.
So here we go :-
The Guide
We will suppose you have two domains my-first-domain.com and my-second-domain.com and you want each of them to refer to a separate website (different users, different content, .. etc) sharing the same Drupal core files
- 1. Install Drupal 7 the normal way
- For this, you only need to upload Drupal core files and create the database (you can use an existing database using table prefixes) and then navigate to the base URL, then just follow instructions
If you have a shared hosting account somewhere, you will most likely have a one-click install for Drupal, this will finish the installation process for you.
Example Linux installation process if this is your local server (or if you have full control)
$ wget http://ftp.drupal.org/files/projects/drupal-7.19.tar.gz
$ tar -xf drupal-7.19.tar.gz
$ mv drupal-7.19 /var/www/drupal
$ mysqladmin -u root -p create drupaldb
Here is a complete installation guide from Drupal website.
- 2. Change DNS records so that the second site's domain points to the same IP.
- If you got the domain from your web hosting provider, then you don't need to bother about this step, If not, this usually means to make sure the name servers of your domain are the ones of your host provider, this is usually found easily in their FAQ, knowledge base, or by contacting them in worst conditions, you may have this already done. (local server, you need to add an A record in your domain's DNS records to point to your machine's IP)
- 3. Configure the web server so that the second site's domain points to the same directory.
- Different web hosting providers has a different procedure for this (usually adding an add-on domain and changing its root directory to your Drupal installation root directory), If, however, you are working on your local server, supposing it is Apache, just add the second site's domain to ServerAlias directive. (or if you need separate logs, you can make a new virtual host with the same DocumentRoot)
Here is an example of Apache configuration..
- Using one host with ServerAlias :
<VirtualHost *:80>
ServerName my-first-domain.com
ServerAlias my-second-domain.com
DocumentRoot /var/www/drupal7
</VirtualHost>
- Or using two hosts for separate logs or other configuration :
<VirtualHost *:80>
ServerName my-first-domain.com
DocumentRoot /var/www/drupal7
</VirtualHost>
<VirtualHost *:80>
ServerName my-second-domain.com
DocumentRoot /var/www/drupal7
CustomLog /var/log/apache2/second-access.log combined
ErrorLog /var/log/apache2/second-error.log
</VirtualHost>
- 3. Make a new directory with name equal to the second site's domain under Drupal's sites directory.
- Suppose you have uploaded Drupal files in a folder named "drupal" so there is "drupal/includes/","drupal/misc/","drupal/modules",..etc. now your new directory should be "drupal/sites/my-second-domain.com". (the folder name is "my-second-domain.com")
- 4. Copy default.settings.php to the new directory renaming it to settings.php and make a new directory called files there then change permissions so that both are changeable by everyone.
- Following what we previously supposed, you will copy the default.settings.php file (found in drupal/sites/default/) to /drupal/sites/my-second-domain.com/ and rename it to settings.php then change its permissions to 666 (make it changeable by everyone) and then make a new directory under /drupal/sites/my-second-domain.com/ and name it "files" then change permissions of it to 777.
In Linux (if you are working on your own local server or have SSH access to your host) this can be done as follows :
$ cp drupal/sites/default/default.settings.php drupal/sites/my-second-domain.com/settings.php
$ chmod 666 drupal/sites/my-second-domain.com/settings.php
$ mkdir drupal/sites/my-second-domain.com/files
$ chmod 777 drupal/sites/my-second-domain.com/files
- 5. Navigate to the second site's domain and install Drupal normally.
- Just like the first step above.
Congratulations, you have a working drupal7 multisite !!
Other Drupal 7 multisite guides and tutorials