Drupal is a powerful open source content management system (CMS) that you can use to handle multiple domains of one Web server. Multi-Sites is a feature by Drupal that enables you to manage many websites much easier. With multi-sites, the user can have several websites with several databases or they can have several websites with one database. So sometimes it can be frustrating & not so clear how to set up multiple sites. In this tutorial, we will show the setup of two subsites with different URLs. Below in this tutorial, we will show you two options to guide you through the necessary steps, but before it, please do make sure you find a Drupal hosting that supports multi-sites.
Drupal Multiple Site – Option A
Follow the structure below:
- Master site: https://kingweb.com
- Sub-site 1: https://queenweb.com
- Sub-site 2: https://jackweb.com
To make life easier we will show you how to set up your hosting account with commonly used cPanel, the setup process with vary if you use Plesk, ServerCP etc.
1. Choose master domain & create databases for all the sub-sites
- Firstly house the URL that will host your main website for this tutorial it will be i.e. https://kingweb.com
- For each site you want to add, Go to MySQL in cPanel or use the database wizard to create the databases.
- NOTE: Make sure the user has full privileges to each database.
2. Install Drupal in your master URL directory
- Install Drupal in your /public_html/ directory.
- Visit the URL – In this case https://kingweb.com & go through the Drupal installation.
- Use the master database connection information when the install script prompts to.
3. Create a sub-folder for each sub-site
- Create a folder under public_html/sites/subsite.com. Substitute the URL that you’ll use.
- Create one folder for each sub-site.
- Copy default.settings.php to each one.
- CHMOD those files to 644 if they aren’t already.
- NOTE: Drupal 6 users: You should also create an additional folder called “files” and make sure it’s CHMOD 755.
4. Copy or upload default.settings.php to the new folders
- Add default.settings.php to your new folders.
- NOTE: Drupal 6 users: create a files directory with the path sites/domain.com/files/. You don’t need this extra directory here for Drupal 7.
- Upload or copy default.settings.php to the folder.
- Rename it to settings.php.
5. Return to cPanel
- On the main cPanel dashboard, find the Domains section and click Parked Domains.
6. Add the domain
- Park the domains on top of the master domain.
NOTE: When you park a domain, the domain must be pointed at the DNS servers for your hosting account. If you don’t know how to do this, contact your hosting company.
7. Go to your browser & visit the URL
- Type the URL to your second or third site.
- Install Drupal by following the prompts.
8. Connect to the proper database
- When prompted, enter the database information for this specific site. Make sure everything matches:
- Database type*
- Database name*
- Database username*
- Database password*
That’s it! The three sites https://kingweb.com, https://queenweb.com, https://jackweb.com, each with their own modules & all on the same web hosting account. If you want to create another website, then just repeat the process.
Drupal Multiple Site – Option B
Go back start steps 1 & 2, because everything is the same from that point. Now in Step 3, we start to take a different turn.
1. From Step 3. Create directories for each domain with – convention subdomain.domain.com
- Create folders for each site you want to create.
- Create the folder names with this convention subdomain.domain.com.
- Upload or copy default.settings.php to each directory.
- Change the name of each copy to settings.php.
- Return to cPanel home.
2. Create subdomains
- Navigate to the Domain section & click Subdomains.
NOTE: Make sure you see the directories created by cPanel & the directories created by yourself.
3. Execute a basic php script to create a symlink
- In a script editor create a file named “mysymlink.php” & input the following code:
Symlink( ‘/home/cPanel_User_Name/public_html/’, ‘subdomain’ );
- In this case, my case file would look like this:
Symlink( ‘/home/myuserdirectory/public_html/’, ‘queenweb’ );
Symlink( ‘/home/myuserdirectory/public_html/’, ‘jackweb’ );
4. Upload symlink script to the main directory
- To Run, visit your browser address bar & enter your URL & the name of the file, i.e. https://kingweb.com/mysymlink.php
- You will see a blank page, if you did make any mistakes you would actually see the error messages displayed.
5. .htaccess file – Add redirection
- Open your .htaccess file in a script editor
- Find the line # RewriteBase/ and remove the # sing.
- Add the following line and save the changes:
RedirectMatch 301 ^/subdomain/(.*)$ https://subdomain.yoursite.com $1
- Here’s what my .htaccess looked like:
RewriteBase / RedirectMatch 301 ^/queenweb/(.*)$ https://queenweb.kingweb.com/$1 RedirectMatch 301 ^/jackweb/(.*)$https://jackweb.kingweb.com/$1
- The redirection will enable the site to be accessible in two ways.
- https://kingweb.com/jackweb & https://jackweb.kingweb.com will both be redirected to the same site.
6. Visit your subdomain & complete the Installation
- Now visit your subdomain & you be prompted to install Drupal in your subdomain.