Multi-site setup using CPanel

Last modified: September 21, 2008 - 01:38

After some searching around, I found out how to do multi-site setup using CPanel.

1. Create your initial Drupal site at www.yourdomain.com. Drupal 5.x makes this very easy to do, as it will automatically install the database for you -- all you have to do is input the database information.

2. Create a folder in the sites/ folder that matches the subdomain you want to create (so for site1.yourdomain.com, the folder name would be site1.yourdomain.com).

3. Duplicate the settings.php file from the default folder and place it in your newly created folder from step 2.

4. Edit the settings.php file you just placed in the site1.yourdomain.com folder so that it does not point to a database. You can replace the line that has your other site's database information with this:
$db_url = 'mysql://username:password@localhost/databasename';
This will allow step 9 below to load your database tables.

5. In CPanel, set up the subdomain. For the above example of site1.yourdomain.com, a folder named site1 will be automatically created by CPanel.

6. Delete the folder that was created.

7. Use the following example to create and upload a php file onto your site. An easy way to do this is to use Notepad, pasting in the text below, editing as necessary, and then saving as multisite.php. Afterwards, upload via FTP or CPanel's File Manager. Make sure you change the path to whatever the path to your web root is.

<?php
symlink
( '/home/username/public_html/', 'site1' );
?>

8. Go to the location of the php file in your browser (such as www.yourdomain.com/multisite.php)

This will create a symlink, allowing your subdomain to work properly.

9. Go to your subdomain. Drupal will ask for your database information and then install the tables necessary to run the new site.

10. You're all set to use the new site.

If you run into any problems, or have questions, use the contact form attached to my user account here to contact me.

setting up the symlinks via SSH

JohnG - March 8, 2007 - 18:48

I had a problem with the multisite.php method because my hostserver was giving me 'denied permission' when I tried to add symlinks to the root directory - apparently the symlinks must go in the root to work! I ended up (on advice from hostserver support) using PuTTY to set up the symlinks via SSH. They were very nice and gave me idiot-proof instructions. I don't know if this will work for everyone's hostserver configuration, but I'll share in case it helps someone:

1. Set up the subdomains (subdomain1, subdomain2) using c-panel.

2. In file manager home/username/public_html (your Root directory) you now have these interesting folders:
public_html/drupal5
public_html/subdomain1
public_html/subdomain2

(this next bit is an alternative method for steps 6, 7, and 8 in the handbook page version above)

3. Point your SSH client (I used PuTTY in SSH mode) at your domain eg "example.com". - and log-in:
- Username = your c-panel username
- Password = your c-panel password

4. At the command line prompt, type each line then hit 'Enter':

cd ~/public_html
rm -Rf ./subdomain1
rm -Rf ./subdomain2
ln -s ./drupal5 ./subdomain1
ln -s ./drupal5 ./subdomain2
ls -la

note: " rm -Rf ./subdomain1 " deletes the folder which c-panel created ...
and : " ln -s ./drupal5 ./subdomain1 " creates the symlink in its place ...
and : " ls -la " gives you an overview of the folders and symlinks etc in the current folder (public_html)
so if you want to delete a symlink eg subdomain_error use " rm -Rf ./subdomain-error ".

It worked for me :) Hope it helps someone else.

Setting up multiple installations with fantascico

jas8t123 - June 20, 2007 - 22:31

- I used fantastico to create a new installation and told it my subdomain name.
- Fantastico created a new file structure under public_html/subdomain
- The only thing I had to do was update the following:
$base_url = 'http://subdomain.domain.org'; // NO trailing slash!
to
$base_url = 'http://domain.org/subdomain'; // NO trailing slash!

Then, I redirected my subdomain to this directory and presto! It worked!

Fantastico Revisited

kenlyle - November 22, 2007 - 16:56

Thanks to the above poster for the Fantastico instructions. However, I believe I have found it even easier, using Drupal 5.3:

1)Install the Drupal "base" installation. Just put drupal or some other basic name in the directory name blank in Fantastico.

2)Install your second Drupal instance, say "drupal2"

3)Create a subdomain, i.e. drupal2.yourdomain.com

4)Redirect drupal2.yourdomain.com to http://yourdomain.com/drupal2

5)Repeat 3 and 4 for your additional domains.

I didn't find it necessary to edit the settings.php

Enjoy!
Ken

Yes, but...

nhunter - May 19, 2009 - 16:58

Aren't you installing a complete new Drupal instance?

The topic under discussion is a multisite set-up with a single instance of Drupal.

It's much easier via cPanel

cPanelDavidG - April 23, 2009 - 21:07

Much easier than creating scripts and symlinks, when creating your subdomain just set the document root for that subdomain to be ~/public_html (where ~ represents the house icon displayed in the cPanel interface already).

If you want to create a wildcard subdomain, just enter * as your subdomain.

If you do not see this ability to set the document root for the subdomain, ask your hosting provider to switch your cPanel account to the x3 theme.

YES It's WORK!

hojjat - May 30, 2009 - 04:45

I have problem with symlinks; But this guid help me.
Replace this guide to step 8 and continue, then ENJOY from new site!

 
 

Drupal is a registered trademark of Dries Buytaert.