Drupal supports multi-sites, this means you can install Drupal once and use it for multiple websites (also known as single codebase). This kind of setup will make it easier to maintain your Drupal installation or when you want to upgrade to a newer version as you only need to maintain one codebase. The most common setup seems the subdomain aproach: each website uses its own subdomain. Suppose you want websites for different projects. The layouts and requirements may be different but they will all run on Drupal. The URL's will look like this:http://project1.example.com
There are tons of tutorials on the Drupal site to create this setup but that's not what we are looking for. We want a setup with multiple websites in subdirectories, not subdomains:http://www.example.com/project1
It's a little harder (really only a little) to find how to get this done, let's have a look.
- Start with installing Drupal as you would normally do. Download the latest version and extract it in your server's document root (probably ‘/var/www/html’).
- Create a database and database user for this installation but call it something like ‘project1’ as this will be the database for the first project.
- Configure your installation via the web interface.
That's it, you have your first installation up and running, nothing new here.
Add another instance
- Create a second database and call it ‘project2’. You can use the same user as for the first database but it's obvious that this would be a very bad choice for security reasons.
- Make a copy of the database for the second project (add the -u and -p parameters twice if needed).
mysqldump --opt project1 | mysql -h localhost project2
- Now create the folder structure in your <docroot>/sites directory as explained here. Be careful not to call the directories ‘example1.com’ and ‘example2.com’ as explained in the document but:
- And now the magic... add symlinks for each project in your document root:
ln -s <docroot> project1
ln -s <docroot> project2
Now point your browser to http://www.example.com/project1 and you should see the first site, http://www.example.com/project2 will get you to the second one. At this point both sites will be identical (you copied the database remember?) but you can start changing the contents independently of each other now.