Friday, June 17, 2011

Multi-site configuration


Example 1:
  1. Create dns entries for the sites ( or use hosts file for testing)
  2. Create vhosts in Apache configuration file and restart Apache:
            Listen 80

            DocumentRoot "C:/Program Files/xampp/htdocs"
            ServerName localhost:80

            DocumentRoot "C:/Program Files/xampp/htdocs"
            ServerName www.site1.local:80

            DocumentRoot "C:/Program Files/xampp/htdocs"
            ServerName www.site2.local:80
  1. Create folder sites under drupal/sites
    www.site1.local www.site2.local
        Note: Each site folder can have a file, tmp, modules and themes subfolders.
  1. Copy settings.php from drupal/sites/default to each site folder. Modify $db_url and $db_prefix in settings.php in each site folder.
        For www.site1.local: Single database and db user.
        $db_url = 'mysql://drupal:drupal@localhost/drupal';        
        $db_prefix = 'site1_';
        For www.site2.local: Single database and single db user.
        $db_url = 'mysql://drupal:drupal@localhost/drupal';        
        $db_prefix = 'site2_';
        For www.site1.local: Multiple databases and single db user.
        $db_url = 'mysql://drupal:drupal@localhost/site1';        
        $db_prefix = '';
        For www.site2.local: Multiple databases and single db user.
        $db_url = 'mysql://drupal:drupal@localhost/site2';        
        $db_prefix = '';
        Note: Always use the same db user (the one that you used to install drupal for the first time) independently if you want to have a single or multiples db’s.
  1. Open your web browser and point to the install.php file for each site
        http://www.site1.local/drupal/install.php
        http://www.site2.local/drupal/install.php
  1. Edit the /etc/hosts and add the following lines
        10.123.11.61 www.site1.local
        10.123.11.61 www.site2.local
  1. Your new sites are ready using a single code base, single db user and single or multiple db’s.
        http://www.site1.local/drupal/
        http://www.site2.local/drupal/


Example 2:
    1. Create folder sites under drupal/sites
          www.site1.local www.site2.local
    2. /etc/apache2/sites-available/site1.local will be
                                DocumentRoot /var/www/drupal613multisite
                                ServerName www.site1.local
                                ErrorLog /var/log/apache2/error.log
    1. Make link to ln -s /etc/apache2/sites-available/site1.local /etc/apache2/sites-enabled/site1.local
    2. /etc/apache2/sites-available/site2.local will be
                                DocumentRoot /var/www/drupal613multisite               
                                ServerName www.site2.local
                                ErrorLog /var/log/apache2/error.log               
    1. Make link to ln -s /etc/apache2/sites-available/site2.local /etc/apache2/sites-enabled/site2.local
    2. Edit the /etc/hosts and add the following lines
                10.123.11.61 www.site1.local
                10.123.11.61 www.site2.local
    1. In /etc/apache2/sites-available/default add the following line in top of the file
                NameVirtualHost *
    1. Restart apache server.
    2. Run http://www.site1.local and http://www.site2.local

No comments:

Post a Comment