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)

Domain names and IP addresses


The first thing we need to be able to do is correctly correlate the many sites in a multi-site configuration so that each site is accessible separately. Largely, we are concerned with the process of mapping multiple domain names to a single server. Chances are, if you've ever run a website before you will be familiar at least in part, with the concepts here, but to make sure we're off to a solid start, I will give a very brief explanation of how domain names need to be configured, and how they are related to an IP address. But the process of configuring a TCP/IP stack varies from environment to environment. Here we will only look at configuring host names through a system's hosts file—a file resident on the operating system that tells the networking layer how to find certain domain names.

In the TCP/IP networking stack, the function of an IP address is to provide a location identifier for a network interface on a network. When your computer makes a request for a network resource, the request is sent from your computer's networking interface out over the network. Routers, switches, and other pieces of network equipment transport the message over a series of network links until it arrives at the remote networking interface, at which point that computer handles the request. It then returns data through its network interface, and that message is again relayed through the network back to the initial requesting interface on your computer.

One helpful analogy for this process is the physical mail delivery service. A network interface plays (roughly) the role of a mail box. When you drop a letter in the box, it is picked up by the postal service, and channeled through a series of post offices (much like the switches and routers). Finally, it is delivered to the destination post box. And a letter in reply follows that same process back.

Just as a mailbox has a postal address, a network interface on a TCP/IP network has an IP address. This is used by the network to determine crucial things about the network interface, such as what network it is on, and where in that network it is located.

A domain name is conceptually one level higher. A given IP address can have more than one domain name, just as a large building may have one address, but many businesses occupying it. And when a business moves to a different building, the address will change, but the business name does not. Analogously, the relationship between a domain name and an IP address is not necessarily permanent. The domain can move from one address to another.

But something on the network needs to know how to map a domain name to an IP address. This role is often handled by a series of servers called Domain Name Service (DNS) servers. A DNS server is responsible for mapping a subset of the total domain names to IP addresses. There are thousands upon thousands of DNS servers on the Internet. Each is responsible for a certain portion of IP address-to-domain-name mappings. And the DNS system is structured in such a way that when a client requests information on a mapping, it will get an answer even if the authoritative DNS server is on the other side of the planet.

So when you type in a URL in your browser, chances are good that one of the first things your browser does is send the domain name (www.example.com) off to a remote DNS server, which will respond with an IP address (10.21.77.101). From there, your computer's networking software will know how to send requests out to that remote host.

Note

IP addresses and domains

It is possible for a single computer to have more than one IP address. And it is possible for a web server, like Apache, to listen for traffic on more than one address. Because of Apache's flexibility, it is possible for Drupal to piggyback on this functionality, and handle sites on multiple IP addresses.

In a multi-site configuration, then, one of the things you will need to handle (regardless of what software you use to host your website) is ensuring that all of the sites on your multi-site have domain names configured. Sometimes this means changing a DNS server on your local network, or requesting that your network admin do this for you. When using a web hosting provider, you can often request that they handle this mapping for you. And sometimes this means requesting a change from your domain name's registrar (the place in charge of handling your domain name registration—places like GoDaddy or Verisign).

Using a hosts file

While the nuances of configuring DNS are beyond the scope of this chapter, we can take a shortcut that will allow us to proceed with our own development.

When building multi-domain sites, you may not need to change any remote DNS servers. You may be able to simply add or modify an entry in your system's hosts file. This file contains a set of domain name mappings specific to your computer only. But be warned: when you use this method, it will only impact the computer on which you make the change. Other computers will not have the same mapping.

Note

Once you are done building and need to make the site public, you will need to configure a DNS server. Contact your network administrator or web service provider to find out how to add your mappings to their DNS services.

In the case where you are running multiple local sites on your computer, you can map these names like this:

127.0.0.1 localhost books.local looks.local cooks.local

The format of the snippet above is this: The IP address goes first. Your computer always has a self-referential address of 127.0.0.1 (the loopback address). Next come one or more domain names separated by spaces. So the example above says that four domain names (localhost, books.local, looks.local, and cooks.local) all reside on this computer. Any traffic to any of these domains should be "looped back" to the computer itself and handled locally.

Note

If you are following the VirtualBox/Vagrant installation method, we made a similar configuration, but assigned 33.33.33.10 to the hostnames books.local, looks.local, and cooks.local instead of to 127.0.0.1.

The bottom line is this: To use a multi-site configuration with multiple domains, something (a DNS server or a host's file) must be able to handle that lookup from each and every domain name you wish to use to an IP address on your server.