Monday, February 27, 2012

Multi-site on Windows


Software







This guide assumes you have installed WAMPServer, which you can download below:

Alternatively, you can install another WAMP package, but you will need to adjust the paths as necessary.

Process



  1. Set up Drupal as usual

    1. Install WampServer (or another 'WAMP' package) and make sure that Apache and MySQL services are running.

    2. open phpMyAdmin in your browser localhost/phpmyadmin (or it can be launched via the WampServer icon in your system tray.)

    3. Create a new database -- we'll call it drupal6 because this will be our base installation which we will leave untouched. While you're here create a second and third database, which we'll call site1 and site2. You can also change the database privileges if you want, but to keep things simple here, we'll stick with the default user root and no password.

    4. Download Drupal 6 into WampServer's wamp/www folder (or the htdocs folder in Xampp and some other packages). (You'll need a tool like 7-zip to unpack the Drupal tar.gz file).

    5. Do your first Drupal installation by pointing your browser to your Drupal folder, which should be something like http://localhost/drupal-6.x. Enter the drupal6 database and user settings (root and no password in this example). Complete the installation, but then leave it alone.



  2. Prepare the files for your new multi-sites

    1. Find Drupal's sites folder, make a copy of the default folder and rename it to the URL you want for your first test site. To keep it simple, we'll make it the same as the first test site database: site1. While you're here, create files, tmp and themes sub-folders within this new folder. The themes sub-folder will be used for any custom theme you create specifically for this site. Similarly, you can create a modules sub-folder for any module you use only with this site. However, generally, I find it easier to keep all contributed modules together in the sites/all/modules folder so I can use them with all my test sites.

    2. Use a text editor to open the settings.php file in your new site1 folder and change$db_url line to reflect your first test site database, and the database user name and password, eg:
      mysql://username:password@localhost/site1
      Also, change the $base_url to the above site URL, eg:
      $base_url = 'http://site1'; // NO trailing slash!

    3. Repeat the above 2 steps for the other test site (site2)



  3. Adjust windows so it can find the new site at a new made-up nameFind the Windows hosts file, which should be in Windows' System32/drivers/etc folder, make a backup of that file and then open the hosts file in a text editor. Here, add new lines mapping your localhost IP address to match the URLs of your test sites and your original Drupal site. In our example, it would look like this:
    127.0.0.1 localhost
    127.0.0.1 site1
    127.0.0.1 site2
    127.0.0.1 drupal6

    This is telling Windows Networking that http://site1/ is a name for this machine.

  4. Adjust Apache so it responds to requests for the new names

    1. Find the Apache httpd.conf file which, in WampServer, should be in thewamp/bin/ApacheX.X/conf folder (where X.X is the Apache version number). Sorry, I can't remember where Xampp installs this, but it will be in the Apache folder. Anyway, all you need to do with this file is make sure the "Virtual hosts" line is active by removing the # before Include conf/extra/httpd-vhosts.conf.

    2. Make a backup of that httpd-vhosts.conf file (which is in Apache's conf/extrafolder), then open httpd-vhosts.conf with a text editor and add these lines:
      <VirtualHost *:80>
      DocumentRoot C:/wamp/www/drupal-6.x
      ServerName site1
      </VirtualHost>

      where C:/wamp/www/drupal-6.x is the path to the Drupal installation folder andsite1 is the URL for your first test site. Add another entry for your other test site, another entry for your original Drupal installation and another entry for WampServer's localhost URL (if you want to keep this active), eg:
      <VirtualHost *:80>
      DocumentRoot C:/wamp/www/drupal-6.x
      ServerName site2
      </VirtualHost>

      <VirtualHost *:80>
      DocumentRoot C:/wamp/www/drupal-6.x
      ServerName drupal6
      </VirtualHost>

      <VirtualHost *:80>
      DocumentRoot C:/wamp/www
      ServerName localhost
      </VirtualHost>

    3. Restart Apache for the changes to take effect. With WampServer, this is done by selecting the WampServer icon in the system tray and then "Restart all services".



  5. Now you're ready to install each Drupal test site using your browser, eg:
    http://site1/install.php
    http://site2/install.php


And that's it. You can access your two test sites anytime WampServer is running by using the http://site1 and http://site1 URLs.

As I said, it's not exactly simple, but it is well worth the effort. Now you can do whatever you like with your test sites. If you mess up with, say, site1, just delete the site1 folder, thesite1 database in phpMyAdmin and the site1 entries in the Windows hosts and Apachehttpd-vhosts.conf files and start again. Alternatively, if a site works out and you want to go live with it, the multi-site approach makes this easier (in my opinion).
One final caveat: I'm no expert. This technique works for me (apart from one corporate environment with a particularly annoying proxy server), but I'd welcome any feedback, especially if there are any accuracies.




1 comment:

  1. how to use an other port that port 80 in hosts and virtualhost?
    thank

    ReplyDelete