Hello Friends,
I am new to Drupal and creating cms with multiple sites.
I have installed drupal and created one site its working fine, ie. http://www.mysite.com and now i have to add one more subdomain in my site i.e. http://www.mysite.com/test. But i have to use only one database which i have already created for my first site.How can i do this? Is it possible?

Please help me.
I am waiting for your valuable guidance.

Thanks in advance.

Aniket.

Comments

MM10’s picture

Hi Aniket,
I don't think I can help much but perhaps offer a cautionary note. I was in your exact same position earlier today and followed (or mis-followed!?) some instructions from a poorly documented site on this.

My 6.8 website was up and working just fine and I sought to crete my second site. I followed these instructions:

* Step 1: After installing Drupal 6 and setting it up along with the main domain, it‚s time to choose the second domain to be used.
* Step 2: After choosing the second domain, you will have to point it to the root directory of Drupal.
* Step 3: Under the /sites directory, create a new folder and name it exactly as your second domain to be used. (e,g. ../sites/seconddomain.com)
* Step 4: Under the /sites/default directory, a file named „settings.php‰ exists. Copy that file and place a copy of it under the newly created sub-directory (e.g. ../sites/seconddomain.com/settings.php)

I then tested it and all seemed fine at first: I created a 'test' page content on one site and it did not appear on the second. Seemed fine. I then changed the default theme on my new site and checked my other site--- only to find that it too changed!

Now here is the prt where I think I made mistake: I copied and moved the module and theme directories out of the sites/all/ and placed them in my new /sites/seconddomain.com/ directory (as part of following some poor instructions).

Now both sites are not working and I my site front page does not appear, instead I see:

Fatal error: Call to undefined function user_access() in /Library/WebServer/Documents/sites/all/modules/admin_menu/admin_menu.module on line 90

After a bit of digging around, I see that moving module and theme directories is a no-no? To fix things, I am considering following some ideas posted on
http://drupal.org/node/339613 and http://drupal.org/node/26256 but m somewhat hesitant based on my last slip-up. Also I am not an expert here...

If anyone has any advice, it would be much appreciated, as it is sad to have a broken Drupal!

Mike

ChrisBryant’s picture

You have two options here, normally for Drupal multisite all you need to do is create another folder in the "sites" folder and make sure it has it's own "files" folder and it's own settings.php (you can copy the default folder and rename it if you need to.)

In this case if you want to have the second site at http://www.mysite.com/test then you either need to have that be a separate install (entire copy of the main Drupal folder) or setup some Apache Rewrite rules in your .htaccess file.

In order to have multiple Drupal sites with the same database you just need to use database prefixes in the settings.php file. See the comments in the settings.php file for more info:

 * You can optionally set prefixes for some or all database table names
 * by using the $db_prefix setting. If a prefix is specified, the table
 * name will be prepended with its value. Be sure to use valid database
 * characters only, usually alphanumeric and underscore. If no prefixes
 * are desired, leave it as an empty string ''.
 *
 * To have all database names prefixed, set $db_prefix as a string:
 *
 *   $db_prefix = 'main_';
 *
 * To provide prefixes for specific tables, set $db_prefix as an array.
 * The array's keys are the table names and the values are the prefixes.
 * The 'default' element holds the prefix for any tables not specified
 * elsewhere in the array. Example:
 *
 *   $db_prefix = array(
 *     'default'   => 'main_',
 *     'users'     => 'shared_',
 *     'sessions'  => 'shared_',
 *     'role'      => 'shared_',
 *     'authmap'   => 'shared_',
 *   );
 *
 * Database URL format:
 *   $db_url = 'mysql://username:password@localhost/databasename';
 *   $db_url = 'mysqli://username:password@localhost/databasename';
 *   $db_url = 'pgsql://username:password@localhost/databasename';
 */
$db_url = 'mysql://username:password@localhost/databasename';
$db_prefix = '';

I hope that helps.

--

Gravitek Labs

MM10’s picture

Thanks for the clarification.
Any idea on how to fix my current situation?
Now that I have put my modules and themes folders back in their proper place, how do I get the site back up again?
thnx
mike

MM10’s picture

um, I figured this out.
I needed to go into phpmMyAdmin to replace some of my tables. Apparently Drupal changed the module paths in the tables to reflect my noobie move of the modules directory.

nick_wayne’s picture

Aniket,

The best way to do a multisite is to keep seperate database for each site. This way it will be easy and clean. It will be much easier for upgrades etc also.

Check out http://drupal.org/node/290768

TooLERP - Best Small Business ERP Accounting Software

dman’s picture

Yes, that's a fix.
In the future, note that Drupal can self-heal when you do things like that (sometimes there are good reasons to do this).
As long as you haven't totally destroyed your site, visiting /admin/build/modules and saving will reset your module paths correctly.
When I'm preparing to do this, I usually open that page in the browser, make the filesystem change, then refresh the page and submit.
Same thing works for themes.

chrisa625’s picture

Hey Chris I am doing something similar and need to set up multiple drupal sites using one database. When I change the db_prefix in the settings.php file to be an array, on the page during install that prompts me to choose a database I get 2 warnings:

"Warning: preg_match() expects parameter 2 to be string, array given in /mypath/includes/bootstrap.inc on line 771

Warning: Cannot modify header information - headers already sent by (output started at /mypath/includes/bootstrap.inc:771) in /mypath/includes/common.inc on line 141"

Since they are just warnings I continued wondering if it just would work and it added the tables to the database with no prefix. When I checked the settings.php file the $db_prefix was set to ''; Here is the way I put my array in the settings.php file:

$db_prefix = array(
      'default'   => 'test3_',
      'users'     => 'main_',
      'sessions'  => 'main_',
      'role'      => 'main_',
      'authmap'   => 'main_'
    );

I am using Drupal version 6.12 . Just wondering if this has been seen before or if I'm missing something obvious.

Thanks for any help.
Chris

mandclu’s picture

I continued to get the same warning, and had to take the drastic step of hacking core to make them go away. I have to say I'm a little frustrated that the documentation advises us on a multi-site installation to set the db_prefix as an array, but when you do you get all these errors because there's code that doesn't seem to anticipate that the value could be anything other than a string.

I went into common.inc and changed lines 492-494 from:

  if (preg_match("/simpletest\d+/", $GLOBALS['db_prefix'], $matches)) {
    $defaults['User-Agent'] = 'User-Agent: ' . $matches[0];
  }

to:

  if (is_array($GLOBALS['db_prefix'])) {
    if (isset($GLOBALS['db_prefix']['default'])) {
      // use the default if defined
      $prefix = $GLOBALS['db_prefix']['default'];
    }
    else {
      // otherwise use the first value
      $prefix = array_shift($GLOBALS['db_prefix']);
    }
  }
  else {
    $prefix = $GLOBALS['db_prefix'];
  }
  if (preg_match("/simpletest\d+/", $prefix, $matches)) {
    $defaults['User-Agent'] = 'User-Agent: ' . $matches[0];
  }

I'm not that familiar with how SimpleTest is meant to manipulate the db_prefix, however. It may be that if the db_prefix is an array the User-Agent manipulation can be skipped altogether, which would be a much smaller fix. If someone in that know on that could advise, I'd happily roll a patch on this

megmaltese’s picture

And now the heavy stuff: how do I put on a server datas once the website is "ready"?

The scenario is this: I want to work on multiple sites on my computer, and when the site is done I must "extract" it from my database and ftp it to the server... is there any way to do this without becoming mad?

Otherwise what is the way to work on multiple sites without having multiple server installations?

dman’s picture

Do NOT use database prefixing in the same db if you plan to later split the sites off to different destinations. It's possible, but trickier than you need to do in most cases. Can be done with three lines of shell scripting if you like, a search should find an example, or see below.
You don't need multiple server installations, just different databasenames.

It is reasonable to use a prefix, even if the db is to be stand-alone, as that will give you the ability to mix and match hosting eventually, but that's big picture stuff.

Following code illustrates a snippet that does prefixed db name extraction for me. Out-of-context, Incomplete, some assembly required, some error-checking removed for clarity..


function sitesynch_backup_database($settings) {
  extract ($settings, EXTR_PREFIX_ALL, 'LOCAL');
  $backupfilename = "$LOCAL_SITENAME-$LOCAL_SERVERNAME-". sitesynch_format_datestamp() . ".sql";
  $backupfilepath = "$LOCAL_BACKUPDIR/$backupfilename";

  drush_print("{$ACTION}Creating a database backup{$_ACTION} of '$LOCAL_LABEL' as $backupfilename");

  // If using prefixes, we need to filter only them
  $table_list = '';
  if (! empty($LOCAL_DB_PREFIX)) {
    exec("mysql -u $LOCAL_DB_USERNAME -p$LOCAL_DB_PASSWORD -h $LOCAL_DB_HOST $LOCAL_DB_NAME  -e 'show tables' | grep '$LOCAL_DB_PREFIX' ", $tables);
    $table_list = ' --tables ' . join(' ', $tables);
  }

  $command = "mysql -u $LOCAL_DB_USERNAME -p$LOCAL_DB_PASSWORD -h $LOCAL_DB_HOST $LOCAL_DB_NAME -e \"truncate {$LOCAL_DB_PREFIX}watchdog; truncate {$LOCAL_DB_PREFIX}cache;  truncate {$LOCAL_DB_PREFIX}cache_menu;  \"; ";
  // mysqldump requires LOCK TABLES unless we use --single-transaction
  $command .= "mysqldump -u $LOCAL_DB_USERNAME -p$LOCAL_DB_PASSWORD -h $LOCAL_DB_HOST --single-transaction $LOCAL_DB_NAME $table_list   > $backupfilepath ";

  exec($command);
}