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)

Installing a Drupal Virtual Machine with Vagrant


Building a multi-site Drupal installation does not require running Virtual Box and Vagrant. However, I find this sort of virtual machine configuration to be ideal for experimenting with technologies and development environments. And for the sake of this book, using a pre-packaged configuration such as this allows us to quickly setup nearly identical environments.

Drupal.org hosts a project called Drupal Vagrant (http://drupal.org/project/vagrant) designed to get you running on a full LAMP (Linux Apache MySQL PHP) stack with Drupal in a matter of minutes.

For this book, there is a special version of the Drupal Vagrant project (http://drupal.org/sandbox/mbutcher/1356522). It has been tuned and tailored exactly for this book, and you can use it to build an isolated and disposable environment from which you can follow along.

The full instructions for installing this custom version are available at the previous URL, but here is an abbreviated version.

Installing our tailored Vagrant project

The following tools are required to get started:

  • VirtualBox: This is an open source virtualization environment. It allows you to run "virtual" servers inside of your normal operating system.

    http://www.virtualbox.org

  • Vagrant: This is a tool for managing VirtualBox servers. Because it makes it easy to build complex sites with a command or two, we will be using this.

    http://vagrantup.com

  • Git: Git is a tool for handling revisions of source code or configuration files. Many popular software packages, including Drupal, store code inside of Git repositories.

    http://git-scm.com/

You will need to make sure all three of those are installed according to the directions on their respective websites. While this configuration should work on Linux, Mac, and Windows, there have been recent bugs in the Windows 7 version of VirtualBox. Usually, if you stay with the 32-bit version of VirtualBox, things will work fine on Windows as well.

Next you will need to get a copy of the MultiSite Vagrant profile created for this book. The best way to get it is to retrieve it from Drupal.org's Git server (explained here: http://drupal.org/project/1356522/git-instructions). If that doesn't work, you can try to retrieve a Git snapshot and work from there (http://lb.cm/4FJ).

Now you will need to start configuring things. For simplicity's sake, I am assuming that we are working from a UNIX-like shell. Analogous commands are available in Windows, too.

$ cd multisite_vagrant
$ vagrant box add base http://files.vagrantup.com/lucid32.box
$ vagrant up

The first line in the code puts us in the right directory to begin. Next, we install a basic Ubuntu Linux server profile. This is used for building virtual servers. And thirdly, the vagrant up command tells vagrant to install, boot, and configure our server. It is normal for each of these two Vagrant commands to take a long time.

Once the vagrant up command has finished, your host (local computer) will have a virtual machine running with the following:

  • A minimal Ubuntu Lucid server

  • Apache 2.2

  • MySQL 5.1

  • PHP 5.3

  • Lots of extra tools (such as Xdebug, phpMyAdmin, and xhprof)

Drupal 7, Drush (the Drupal Shell) and a few common modules will also be downloaded, but they are not yet installed. We will talk about these more in the next chapter.

Basic configuration for this book

In addition to the basic installation, the MultiSite Vagrant profile also creates three hostname entries and three databases for you.

In the course of this book, we will be creating three independent sites. These sites will be called Books.local, Cooks.local, and Looks.local. Each will have its own database in MySQL too (books_local, cooks_local, and looks_local). The basic host names and databases have already been set up for you. When you ran vagrant up, a script did the necessary configuration in the VM.

But there is still one thing for you to do. You should add the following to your local computer's hosts file (/etc/hosts in UNIX-like operating systems):

33.33.33.10 books.local looks.local cooks.local

This tells your local machine that all of these hostnames can be accessed on your virtual machine.

If you are interested in learning more about the change to the hosts file, it is explained later in the chapter. But as we are focused here on configuring Vagrant we will finish the configuration first.

Connecting to the new Virtual Machine

Now that we have a new virtual machine set up, we can interact with it in several ways.

  • The File System: When the virtual machine is running, all of the files in the multisite_vagrant project are accessible to the virtual machine. That means you can edit them on your host, and have those changes immediately reflected on the virtual server.

  • SSH: The virtual machine is running SSH. Typing the command vagrant ssh will open an SSH connection to your virtual machine, and you can move around on the command line as you would on any Linux box. (Windows users will need PuTTy for this to work. The http://vagrantup.com/ website has instructions.)

  • Web: The virtual machine is running Apache. We set up the site to listen on books.local, cooks.local, and looks.local. So pointing your browser to http://books.local/server-status should bring up an Apache status page. And the same is true of the other two domains.

So immediately you have three ways to connect to your server. You can also connect to other ports on your virtual server (including MySQL's), but the above cover the common cases.

Finally, before we move on, here are a few Vagrant commands you should know:

  • vagrant halt: Shutdown the virtual server. You can start its back up with vagrant up.

  • vagrant suspend: Put your virtual host to sleep. This is very useful, and I highly recommend doing this instead of halting. But it does require around a gigabyte of hard disk space.

  • vagrant resume: Wake your virtual machine up again (after a vagrant suspend).

  • vagrant provision: Re-run the Vagrant build. While it doesn't re-install Linux or reconfigure the core services, it will re-run all of our configuration scripts. With this, we can reconfigure the server without completely rebuilding it from scratch.

  • vagrant destroy: This will ruthlessly delete your virtual machine. You can then rebuild from scratch using vagrant up. It is useful for "do overs".

Vagrant is one option for quickly starting with this book. But since some environments will require manual customization, in the next few sections I will walk through a manual process of configuring hostnames, Apache and MySQL.

If you are running Vagrant you don't need to do these parts. You can skip ahead to the Summary section.