This is the fastest method I can think of to setup a Drupal Multisite with cPanel. No SSH required.

This page assumes the following

  • You know how to use cPanel
  • You know how to create a database user
  • You know how to create a database
  • You know what I mean when I say "yoursite.com" and "subdomain.yoursite.com"
  1. Install Drupal normally in the public_html folder.
  2. Go to the "Sub Domain Manager" in cPanel, create a subdomain. "subdomain.yoursite.com"
  3. Go to file manager and delete that folder cPanel has made for the subdomain.
  4. Create a folder in the /sites/ folder and name it "subdomain.yoursite.com", replacing them with actual names.
  5. Copy "default.settings.php" file from /sites/default/ and paste it to the folder you've just made.
  6. Create a file in the same folder (The one you made) named "settings.php" and copy the code from default.settings.php.
  7. Create a PHP file in /public_html/ folder and put the code referenced below in it. Replace with real names.
  8. Visit the file with your browser by going to yoursite.com/yourfile.php

Reference & Notes
Note 1. yourfile.php - yoursite.com/yourfile.php

<?php
// This will create a Symlink without the need for SSH.
// Zip it and remove the file when done for safety!
// Please notice how it's "subdomain" and not the full url.  This is important!
symlink( '/home/cPanel_User_Name/public_html/', 'subdomain' );
?>

Note 2. When you browse /public_html/subdomain folder, it will loop. This is normal, do not delete the folder!
Note 3. You will want to edit your .htaccess file to redirect from yoursite.com/subdomain. If you don't, and users visit yoursite.com/subdomain, it will show up as yoursite.com/subdomain/subdomain/ and it will loop. Additionally, if they visit let's say "forum" from yoursite.com/subdomain/subdomain, it will show up as yoursite.com/subdomain/subdomain/forum, and this is very bad for SEO. Place this code into your .htaccess file and uncomment this - "# RewriteBase /"

# RewriteBase /
RedirectMatch 301 ^/subdomain/(.*)$ http://subdomain.yoursite.com/$1

Note 4. Don't create any files in your subdomain folder, although it probably won't hurt anything.
Note 5. When you visit subdomain.yoursite.com/subdomain, it will probably bring you to the home page. As good practice, don't create any pages that will be named the same as your subdomain's name.

This process can be done in under 2 minutes if you're fast, and know how to do all the steps properly. To a new Drupal user, it shouldn't take longer than 15 minutes. Hope you cPanel users found this information useful. If you need help with setting up a Drupal Multisite in cPanel (Although this guide makes it simple enough to do it yourself), I'd be glad to help. Use my Contact Form to get in touch with me. I don't mind setting this up because it's a simple process, and I think every lonely domain deserves a subdomain.

Comments

danreb’s picture

 <?php unlink( '/home/cPanel_User_Name/public_html/subdomain' ); ?>
minneapolisdan’s picture

I have used this exact process successfully for Drupal 6, but it's not working so far with Drupal 7, wondering if I need to change something. The sites.php file?

Dan Moriarty
Creative Director and CEO, Electric Citizen
Twitter: @minneapolisdan

drupalsat’s picture

Just followed this tutorial for Drupal 7 and with succes.

The only thing that took me hours was to find the path to my "public_html" directory which has to be written in the symlink (step 7).

Finally I used the variable $_SERVER["DOCUMENT_ROOT"]. That makes the creating of the symlink as easy as pie.

So in step 7 you better use the php code below. You only have to change "subdomain" in the name of the subdomain that you created in step 2.

<?
  $target = $_SERVER["DOCUMENT_ROOT"];
  $link = $target .'/subdomain';
  symlink($target, $link);
?>
CharlieCastle’s picture

With D7 I get this:

"Not Found

The requested URL / was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache Server at xx.mbhco.com Port 80"

Any ideas?

pitxels’s picture

I was trying this tutorial without luck,
and then I found that using automatic Cpanel installers like fantastico, installatron, scriptaculous, etc
they delete install.php and other install files, and that creates a loop with the symlinks for some reason...

--
Drupal Theming at
www.pitxels.com

Frosty29’s picture

A few years late to reply, possibly!
I got the same “/ not found” - when setting up subdomains for Drupal 7 in Cpanel 11 recently. I could not get this method to work, of deleting the subdomain directory and creating a symlink to the same-named subdirectory.
I really don’t know the workings of cPanel (and of course things may have changed over the years), but I could not see the logic of the steps as described.
Instead I created a symlink to direct the subdomain directory to public_html.

So to create demo.mysite.com:
1) I deleted the subdomain directory as created by Cpanel
2) I created a file public_html/makesymlink.php thus:

<?php
// This will create a symbolic link without the need for SSH.
  
#die( $_SERVER["DOCUMENT_ROOT"]);  #run this first (uncommented) to get path : mine was /home/mysite/public_html 
$target = $_SERVER["DOCUMENT_ROOT"];
$link = "/home/mysite/demo.mysite.com";
$setlink=symlink($target, $link);
if ($setlink){  echo "link set to ".linkinfo($link);  } else {  echo "Link failed!";  }

3) I set up the /sites/demo.mysite.com directory in the usual way, with correct database settings for the subdomain in settings.php, and set up Drupal 7 from there.

With this method I did not need to touch .htaccess and had no troubles with any looping etc, as described for the original subdirectory plan. This method is REALLY simple! I have not edited the original post as clearly that method works/worked for some people as was.

davidkp’s picture

Make sure the install.php file has not been deleted.

I stuffed around for a couple of days and then noticed the install.php file was absent...

I'm definitely out of practice!