Multi-site setup in 6.x using cPanel

glennr - July 6, 2008 - 04:46

I'd like to contribute the following to Drupal's documentation, but I'm fairly new to Drupal, so I'm posting it to the forum first. Any sort of feedback is most welcome. . .

Much of this guide comes directly from the excellent Multi-site setup in 5.x using cPanel guide by jsimonis, which works a treat for Drupal 5 installations. Unfortunately, that technique didn't work with my Drupal 6 multi-site installation, but after some relatively minor adjustments, this is how I got it working on my Web host:

1. Create your initial Drupal 6 site. In this example, the URL is www.yourdomain.com and the first MySQL database is site1db.

2. Use cPanel to create a new MySQL database for your second site, which we'll call site2db.

3. Use cPanel's file manager to create a new folder in your Drupal sites/ folder which matches the URL you want for the second site. In this example, in which we want a subdomain called site2.yourdomain.com, we would create a folder called site2.yourdomain.com. (If you prefer the URL to be yourdomain.com/site2, you would create a folder called yourdomain.com.site2).

4. Download and edit the settings.php file from the sites/default folder, replacing the line containing your first site's datbase information with your second site's database details, eg:

$db_url = 'mysql://username:password@localhost/site2db';

Change the username and password, if required, to reflect the cPanel user settings for the second database (site2db). Then upload the edited settings.php file to the new folder you created in step three (site2.yourdomain.com).

5. If you want a subdomain for your second site, create one now in cPanel. For the above example (site2.yourdomain.com), a folder named site2 will be automatically created by cPanel.

6. Delete the folder that was created for the subdomain.

7. Now create a symlink using a PHP file with this syntax:

symlink( 'path-to-drupal-installation', 'subdomain-folder' );

In our example, the PHP file would look like this:

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

Of course, you would change the path to the real path to your root Drupal folder.

8. Save the file as multisite.php and upload it to your site's web root, eg: /home/username/public_html/

9. Go to the location of this php file in your browser (eg www.yourdomain.com/multisite.php). The Web page will appear blank but it will have done its job by creating the symlink.

10. Now use your browser to run Drupal's install.php script on your second site. In our example, we would go to this URL: www.site2.yourdomain.com/install.php.

11. Drupal should now be ready to install.

A couple of notes:

Firstly, our multisite.php file would be exactly the same as the above example if we had opted for this URL for our second site: www.yourdomain.com/site2.

Secondly, this technique works even if your Drupal 6 installation is in a separate folder off your site's web root. I do this myself to enable me to run both Drupal 5.x and 6.x test sites on the same site. For example, if Drupal is installed in a drupal6 folder off the web root, the path in multisite.php would be:

symlink( '/home/username/public_html/drupal6', 'site2' );

However, multisite.php still needs to be uploaded to (and run in) your site's web root, eg: /home/username/public_html/

So that's about it. If there are any inaccuracies in the above, please add a comment here.

on PC

sherifmayika - July 26, 2008 - 18:00

I am trying to do this as mensioned Have drupal6 as main installation and site1.net and site2.net as second and third sites. I have configured virtual host in xampp, I have setup stings.php too, when trying
http://sie1.net/install.php
geting error like this
The requested URL /install.php was not found on this server.

extend a hand please

thanks in advance

sherif
Dreamweaver extension

Try this . . .

glennr - July 28, 2008 - 03:25

My posting above was designed for use on a typical Web hosting provider, with Linux servers running cPanel. I've created another posting for setting up multi-site on a Windows PC. Let me know how you go with this.

It works like a charm, but

sharifudinrizal - August 4, 2008 - 08:12

It works like a charm, but needs to be tweaked a bit if your main site is already in a subdomain.

e.g.
sub.domain.com (main site)
sub.domain.com/site2 (Site 2)

Multisite.php:
symlink( '/home/user/public_html/sub/', 'site2' );

And this is placed and run from the sub directory, instead of the root.

Yes, of course, sorry . . .

glennr - August 4, 2008 - 10:22

I didn't think of that option. I also have Drupal installed in a sub-folder (eg /home/user/public_html/drupal/) but in my setup, I have given each Drupal site its own sub-domain (eg site1.domain.com and site2.domain.com). So in my case, each symlink had to contain the path to the Drupal installation, eg symlink( '/home/username/public_html/drupal', 'site2' ); but needed to be run in the root, /home/user/public_html/.

Not a blank page

novan_as - September 3, 2008 - 09:35

i hit the multisite.php and got this message:

Warning: symlink() [function.symlink]: Permission denied in /home/username/public_html/multisite.php on line 2

do u have any idea?

Change the folder's permissions

glennr - September 3, 2008 - 13:24

Okay, hopefully that's easily fixed by changing that folder's permissions. After step 8 in my posting above:

  • In cPanel's file manager, right-click on the main Drupal folder (public_html in the above example) and change its permissions to 777.
  • Run the multisite.php script as described in step 9. Then, in cPanel's file manager, you should see the symlink appear as a folder (site2 in the above example).
  • Now you should be able to run Drupal's install.php script as described in step 10.
  • Don't forget to change the Drupal folder's permissions back to 755 and while you're cleaning up, delete the multisite.php file, too.

Multi-site setup problem with one.com hosting

derridaisdead - September 4, 2008 - 14:14

Hello there,
Several steps there that unfortunately do not apply to my installation with the hosting I'm using: one.com.
Administration is not with cPanel but something called ilosoft. But that's not really important I guess.

Important difference with your explanation is that executing the symlink script doesn't seem to have any effect. I had no problem testing my multi-site configuration locally. I want to use a subdomain to get to my addtional sites.
In my local setup, I created host names in /etc/host. I created apache configuration files under /etc/apache2/sites-available for each additional site. I had the right Alias directives in it to have the requests been mapped to the drupal root. I had the right directories for each site under the sites directory of my drupal code. So I had something like...

sites/mysite.com with a settings.php
sites/mysubdomain.mysite.com.site1 with a settings.php
sites/mysubdomain.mysite.com.site2 with a settings.php
Evereything works perfectly as long as I test it locally.

But after upload to my webspace on one.com (and after creating a webalias such as mysubdomain.mysite.com with value mysite.com) I always get a not found error after typing http://mysubdomain.mysite.com/site1 or http://mysubdomain.mysite.com/site2. I know the web alias works because http://mysubdomain.mysite.com shows exactly the same as http://mysite.com, the main site. And the uri remains intact (unlike a web forward): http://mysubdomain.mysite.com. I thought this should have been enough for Drupal to decide which site to render. It says in the install script that the url is used to establish the site being requested. In my case, after typing http://mysubdomain.mysite.com/site1, I was hoping I was going to see the site I had seen while testing locally with all relevant files under sites/mysubdomain.mysite.com.site1.
Unfortunately not.
Any idea on how to handle this?

Web-alias and one.com

mi-sjo - October 30, 2008 - 21:17

You can have a look at this thread: http://drupal.org/node/322984#comment-1085359

I am struggeling with the same issue. Url seems to be the same (in the address bar) when using web-alias at one.com.
The url is not passed on, so drupal never checks for other sites in the ~/sites directory.

Mike

Does this support

getmecashbaby - November 4, 2008 - 01:06

Does this support 'universal' users?

No

glennr - November 4, 2008 - 02:42

I received your email, Jake, but I'll respond here, because forums are the right place to ask support questions. . .

Anyway, no, multi-site uses a different database for each site, which means the users are separate too. I think I remember seeing one or two contributed modules that allow sites to share users, so check out http://drupal.org/project/Modules/. An easier option is to just allow (and encourage) use of OpenID.

All was going well but....

tedhammer - January 13, 2009 - 00:45

I got as far as the location of multisite.php in my browser - a blank page appeared as described.

When I directed it to install.php (www.site1.mydomain.com/install.php) I got the 'Drupal already installed...' message!!

Where have I gone wrong?

I even changed the database settings in sites/www.site1.mydomain.com/ folder back to default ('mysql://username:password@localhost/databasename') hoping to get a prompt that a database, username and password should be entered. No joy!

If you have any idea where I am going wrong and can help then please do - I have been going mad trying to get multi site set up and am on the verge of throwing in the towel and just going with multi installation.......

 
 

Drupal is a registered trademark of Dries Buytaert.