How to configure a Drupal multisite setup
One of the core features of Drupal is the ability to run a multisite setup. That means that you can run multiple websites from the same code base. The advantage is that is makes upgrading the core and contributed modules a lot easier and faster, as you just have to upgrade once, rather than multiple times.
There is a lot of information available on how to setup a Drupal multisite. I have read a lot of it, and most of it is very confusing. I have followed many "tutorials" and ended up going around in circles. This morning I finally figured out how to do it, and it is actually very easy if you do not try and over complicate it!
Step by Step Tutorial
I am assuming that you have access to cPanel and phpMyAdmin. If you run Plesk or similar, then this should still work fine for you. This tutorial is based on Drupal 5.7 (but should work with other versions)
These steps will create one primary site and then additional secondary sites. The secondary sites will all run as their own sites with their own themes, and can have their own standalone modules if required.
- Setup the primary site as a standard Drupal installation. I will assume the primary site is called example.com. Create a folder called "modules" in the sites/all folder. Put any contributed modules that you want to install for all of your multi sites in that folder (sites/all/modules). The acutal modules folder that is in the root should only have the core Drupal modules.
- In the sites folder, create a folder with the domain name of your first additional secondary site. I will assume this is called example2.com. So the directory path will be sites/example2.com. It is important that you name the folder the full domain name and not just example2
- FTP the settings.php file from sites/default to your local machine. Then FTP it to sites/example2.com.
- Create a folder in sites/example2.com called "modules". This is where you will put any modules that are to be just for example2.com. Note that any modules that are to be used by all sites can go into sites/all/modules.
- Create a folder in sites/example2.com called "themes". You can put any themes that relate to example2.com here.
- Create a folder in sites/example2.com called "files". Change the permissions to "777"
- In the cPanel, create a database for example2.com. Add the database user (the one used for the primary site) to example2.com and give it all privileges.
- Now we are going to load the database with all the tables needed. I have created a dump of that for you already. Download the dump from the bottom of this tutorial and save it locally. Open it in a good code editor. Go to phpMyadmin and go to the database that you just created. Go to "SQL" and then copy and paste all of the code from the SQL dump into there. Click "Go" and hey presto, your database it ready!
- Now, go to the settings.php file for example2.com. This is in sites/example.com/settings.php. Scroll down until you see this line:
$db_url = 'mysql://username:password@localhost/databasename';
Change the database name so that it is the name of the database that you just created for example2.com
- You now need to point example2.com to your web server. So go to the place that you registered the domain name (the registrar) and change the name servers to point to your web server.
- You can now "park" that domain on top of your primary domain. This is the stage that a lot of people get stuck on. You will see a lot of people suggesting using a Symlink. This can get very confusing and complicated. Parking is much simpler. Go to your cPanel. Click on "Parked Domains". Add example2.com into the "New Domain Name" and click on "Add Domain".
- It may take a couple of hours (up to 24 hours) for your name server change to propagate through the internet, so you may want to grab a coffee now!
- Now, if you go to example2.com, you should get the standard "Welcome to your new Drupal website" screen. You can now create your first user for example2.com and set it up in the usual way.
- Repeat steps 2 to 13 for an additional sites
- When it comes to upgrading Drupal to a new version, you can perform the upgrade on your primary domain. You can also upgrade any contributed modules that are shared across all of your multiple domains in the sites/all/modules folder.
There, that wasn't so hard! If I have left anything off or made any mistakes, please make a comment below and I will make the necessary changes to the tutorial.
UPDATE: The SQL file download does not work. So you can copy and paste the SQL code to create your tables from here:
If you liked this, you'll love my book, Master Drupal Module Development.
"..the must have drupal developers book"
Feeling stuck with Drupal 8 module dev?
Get the free 7 lesson course that will help you get started today without feeling overwhelmed.
- Create Drupal modules with just a few commands using the Drupal Console
- Create custom pages
- Create custom blocks
- Create admin forms
- Demystify routers and controllers
- Bonus material