Book Image

Drupal 7 Multi Sites Configuration

Book Image

Drupal 7 Multi Sites Configuration

Overview of this book

Drupal is one of the most powerful PHP Content Management Systems there is. However, why would you install a CMS for every site you build? With just one copy of Drupal you can host several sites. Drupal has long had multi-site support, and Drupal 7's support is even better than previous versions. Drupal 7 Multi-Sites Configuration will teach you how to host several websites on a single copy of Drupal. You will learn how to create different sites, each with its own domain, content, and theme. This valuable information will help you to save time by managing modules and sharing them across several sites as well as administering your sites all in one place.This book will show you how to configure a system for multi-site, and then install several sites on one copy of Drupal, all with their own domain name and database. Learn how to install and share modules and themes, configure Apache, PHP, and MySQL for multi-site, and then manage the site. Once your site system is successfully set up, discover some of the advanced configurations possible with Drupal multi-site, as well as how to upgrade and maintain your sites.
Table of Contents (11 chapters)

Configuring MySQL


In the previous section we configured Apache. Now we will set up MySQL with three databases—one for each of our sites. Again, if you are using the Vagrant-based virtual host, you will not need to do this part. It has been done already.

Again, we will assume that MySQL is already set up and running, and we will also assume that you can access the MySQL database as a privileged user and create user accounts and databases.

The first thing to do is create three new databases, one for each site. We will call these databases books_local, cooks_local, and looks_local to correspond to our three hostnames.

From a MySQL monitor (such as mysql on the command line), issue the following command:

CREATE DATABASE books_local;
CREATE DATABASE cooks_local;
CREATE DATABASE looks_local;

That is all that is required to create our databases. But we need to explicitly grant permissions for another MySQL user to access these databases. We will configure our Drupal sites to use this account to authenticate to the database. You can create a separate account for each site if you'd like, but we will just create one.

GRANT ALL
ON books_local.*
TO 'drupal'@'localhost'
IDENTIFIED BY 'secret';
GRANT ALL
ON looks_local.*
TO 'drupal'@'localhost'
IDENTIFIED BY 'secret';
GRANT ALL
ON cooks_local.*
TO 'drupal'@'localhost'
IDENTIFIED BY 'secret';

This will give the user drupal, whose password is secret, sufficient privileges to access all three of our databases. Notice that the Drupal account has been restricted to connections from the localhost. This is designed to prevent a remote user from connecting as our Drupal user.

It is a good idea to test these credentials using another MySQL client. This will help us preemptively troubleshoot. Here is an example from a UNIX shell using the mysql client.

$ mysql -u drupal -p secret books_local
mysql> SHOW TABLES;
Empty set (0.00 sec)

The snippet above shows that we connected to the database with our credentials, then successfully executed the SHOW TABLES SQL statement.

At this point, MySQL should be ready for Drupal, and we are done preparing the environment.