Khanh Hoang - Kenn
Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.
This tutorial starts from a scratch Ubuntu 10.04 LTS installation, in to a clean Drupal 7 mult-site installation. Here's what you need to get started:
sudo adduser -G admin <NEW_USER> sudo passwd <NEW_USER>
Now you should have created yourself an account that can use sudo. Exit the shell and relogin as your newly created user. You may need to set up your name and such, you can do that by modifying the /etc/hostnamelike this:
sudo nano /etc/hostname
For an immediate effect, you can execute the following command:
sudo hostname <HOSTNAME>
sudo apt-get install mysql-server sudo apt-get install phpmyadmin
Take note of your password of course, and when choosing a web server select Apache2. Make sure everything is running fine after this, you may need to start the servers like this:
sudo service apache2 start sudo service mysql start
And this point you should be able to navigate to your server's IP or hostname if you have set up your DNS, and it should bring up the index.html file that reads "It Works!."
# To redirect all users to access the site WITHOUT the 'www.' prefix, # (http://www.example.com/... will be redirected to http://example.com/...) # uncomment the following: RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
sudo mv example.sites.php sites.php sudo nano sites.php
Now modify the sites.php to let Drupal know what directories to use for the corresponding hostname, mine may look like this:
<?php // $Id: example.sites.php,v 1.3 2010/04/15 12:01:28 dries Exp $ /** * @file * Configuration file for Drupal's multi-site directory aliasing feature. * * Drupal searches for an appropriate configuration directory based on the * website's hostname and pathname. A detailed description of the rules for * discovering the configuration directory can be found in the comment * documentation in 'sites/default/default.settings.php'. * * This file allows you to define a set of aliases that map hostnames and * pathnames to configuration directories. These aliases are loaded prior to * scanning for directories, and they are exempt from the normal discovery * rules. The aliases are defined in an associative array named $sites, which * should look similar to the following: * * $sites = array( * 'devexample.com' => 'example.com', * 'localhost.example' => 'example.com', * ); * * The above array will cause Drupal to look for a directory named * "example.com" in the sites directory whenever a request comes from * "example.com", "devexample.com", or "localhost/example". That is useful * on development servers, where the domain name may not be the same as the * domain of the live server. Since Drupal stores file paths into the database * (files, system table, etc.) this will ensure the paths are correct while * accessed on development servers. * * To use this file, copy and rename it such that its path plus filename is * 'sites/sites.php'. If you don't need to use multi-site directory aliasing, * then you can safely ignore this file, and Drupal will ignore it too. */ /** * Multi-site directory aliasing: * * Edit the lines below to define directory aliases. Remove the leading hash * signs to enable. */ $sites['gerbino.co'] = 'gerbino.co';
sudo a2dissite default
Now let's tell Apache2 how to handle our http requests by creating a file called /etc/apache2/sites-available/drupal-7.
sudo nano /etc/apache2/sites-available/drupal-7
Here's an exampe of how it should look:
<VirtualHost *:80> ServerAdmin [email protected] ServerName server1.yunices.com DocumentRoot /var/www/drupal/7 <Directory /> Options FollowSymLinks AllowOverride All </Directory> </VirtualHost>
Now we should activate the Virtual Host (which is really just creating a symlink to sites-enabled, but we'll do it the right way).
sudo a2ensite drupal-7
Finally, we must reload Apache2 so the configuration can take effect, you can do this by executing the following:
sudo service apache2 reload
http://<HOSTNAME>/phpmyadmin
Create the new emptydatabase, and go to priviledges and add a user that has full access to your specified new database and nothing else. I also like to limit it from localhost only. Take note of the information such as database name, database user, database user password. Now for each one of your new domains you should be able to navigate to:
http://<DOMAIN.TLD>
And see the Drupal installation script running. Simply following the installation as normal and enjoy your new multi-site setup. Every site will be redirect with or without www as you've modified the Drupal .htaccess, and everything is gravy.