Check your version

This video covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.

Configure Apache for Multiple Domains

Video loading...

  • 0:01
    Configure Apache for Multiple Domains
  • 0:03
    with Addison Berry
  • 0:04
    The example we're going to be using to build out
  • 0:07
    our multi-site is a university site that actually
  • 0:10
    has three different sites that they need to maintain.
  • 0:13
    So we're going to have the main site-- which is udrupal.com--
  • 0:16
    and then we're going to have a news site and an alumni site.
  • 0:19
    Now, the news site is a subdomain, news.udrupal.com,
  • 0:24
    but the alumni site is actually a completely different domain
  • 0:27
    name, so that's drupalalumni.com.
  • 0:30
    So we're going to need to get all of these things mapped together
  • 0:34
    so that those domain names actually point to the directory
  • 0:38
    that we need on our web server.
  • 0:40
    So in this lesson, we're going to make sure that the domain name is
  • 0:44
    pointing to the web server to begin with.
  • 0:46
    That's the first step.
  • 0:48
    Then we're going to go into Apache and we're
  • 0:50
    going to configure our vhost, or our virtual host,
  • 0:53
    file so that that domain name that comes into the web
  • 0:56
    server maps to the correct directory in the web server that's going
  • 1:00
    to eventually deliver our Drupal site.
  • 1:03
    Then we'll install the main Drupal site, udrupal.com,
  • 1:06
    just to get things started and to make sure at least that domain name
  • 1:10
    is all working properly the way that we expect it to be.
  • 1:13
    So the first thing I want to do is make sure
  • 1:16
    that I actually have my prerequisites in place.
  • 1:19
    So we want to confirm the domain names are actually pointing
  • 1:21
    to my server, which is going to be useful.
  • 1:24
    And then, I also want to just make sure I know exactly where my Drupal
  • 1:27
    7 code is on the server that we need to point them to.
  • 1:30
    So in my browser, I'm just real quickly
  • 1:32
    going to go to those domain names and make
  • 1:34
    sure that that's working properly.
  • 1:36
    So this is udrupal.com.
  • 1:39
    And you can see that I'm getting my Server Message.
  • 1:41
    This is the message I happen to have on my server.
  • 1:43
    It could be different.
  • 1:44
    You could put something specific in there
  • 1:46
    to make sure it's hitting yours.
  • 1:47
    But since it's not getting a Page Not Found,
  • 1:49
    it is actually pointing to my server.
  • 1:51
    You can see this is the alumni site, same Server Message.
  • 1:56
    And then we get news.udrupal.com.
  • 1:59
    Again, these are all pointing to the same Apache server
  • 2:02
    that I can play with.
  • 2:04
    So that's good.
  • 2:05
    Second thing is make sure we actually know where our code is.
  • 2:08
    So I'm going to go ahead and go over to my terminal.
  • 2:11
    I'm doing this on a server using SSH,
  • 2:14
    so I'm going to be in the terminal for this.
  • 2:16
    But of course, if you're working locally or somewhere else,
  • 2:18
    you can use whatever tool you need to navigate
  • 2:20
    around and edit the things that you need.
  • 2:23
    So this is the my Drupal installation.
  • 2:25
    You can see I'm doing a listing of the files,
  • 2:27
    so this is my Drupal root.
  • 2:29
    It's important that I know where on the server,
  • 2:31
    what is the full path to my Drupal installation.
  • 2:34
    So I'm going to just do a pwd, and that's
  • 2:37
    going to give me the actual full path to where my Drupal code lives.
  • 2:41
    And we want our domain names to be able to point to that directory.
  • 2:46
    That's why that's going to be an important thing for us to have.
  • 2:49
    So with these two things in place, let's go configure Apache
  • 2:52
    to get it all actually lined up and working together.
  • 2:55
    Again, where you configure Apache, where your vhost file lives,
  • 2:59
    is going to depend on your server and your different setups
  • 3:02
    that you're using.
  • 3:03
    I happen to be using Ubuntu on this particular site.
  • 3:07
    So I'm going to go to /etc/apache2, that's where
  • 3:13
    all my configuration is.
  • 3:15
    You notice that we have an httpd.conf file, which
  • 3:19
    is the standard, old-school Apache configuration.
  • 3:23
    There's also an apache2.conf, which is where
  • 3:25
    the main configuration is for Ubuntu.
  • 3:29
    But the vhosts are stored in a separate file that
  • 3:32
    is then sucked into the apache2.conf.
  • 3:35
    So I'm not going to edit that file.
  • 3:37
    Here, the way that Ubuntu does this, we have sites-available
  • 3:40
    and sites-enabled.
  • 3:41
    And that's where the vhost files live.
  • 3:43
    So I'm going to go into sites-available.
  • 3:46
    And you'll see we have a number-- we have default
  • 3:47
    and I have a couple of other sites already running on this server.
  • 3:51
    Each of these files contains a vhost for a site or a set of sites.
  • 3:55
    I can set this up and organize these files any way I want.
  • 3:59
    This gets into how you want to set up things on your server.
  • 4:02
    I can create a file for each vhost separately
  • 4:04
    or since these are all pointing to the same directory on the server,
  • 4:09
    I can create just one file for all three of them.
  • 4:14
    For this demo, that is going to be the simplest and fastest thing,
  • 4:17
    so I'm going to go ahead and do that.
  • 4:18
    But how you organize this is really up to you.
  • 4:21
    So I'm going to create a new file here.
  • 4:23
    And I'm just going to call this one udrupal.
  • 4:27
    So we'll do this.
  • 4:28
    I get an empty file.
  • 4:29
    And I'm just going to paste in the vhost directive
  • 4:33
    that I already have created here.
  • 4:36
    So I'll insert and paste this in.
  • 4:39
    Again, you can do this however it is that you need to for you.
  • 4:43
    And again, this is just the virtual host directive,
  • 4:45
    so we can walk through this quickly, just
  • 4:48
    so you are clear what I have here.
  • 4:49
    But I have the admin email address, the main server name-- which
  • 4:54
    is udrupal.com-- and then other aliases.
  • 4:57
    So these are other domain names that are going
  • 4:59
    to alias to this same, central server.
  • 5:03
    And the important here, other than listing the domain names,
  • 5:08
    is making sure that we have this document root identified
  • 5:12
    with that full path to my Drupal root directory.
  • 5:16
    So that's what we need there.
  • 5:18
    And then we have some options here for allowing things
  • 5:21
    to work, you know, with Drupal and making
  • 5:23
    sure the symlinks work and such.
  • 5:25
    So, all we do, put this in here.
  • 5:27
    Put it into the file.
  • 5:28
    I'm going to go ahead and save this.
  • 5:32
    And now you see I have this file for udrupal.
  • 5:35
    And what I need to do on this particular server
  • 5:38
    is enable this vhost so that Apache is
  • 5:42
    aware that I actually want to use it.
  • 5:45
    So this is just a quick command here.
  • 5:49
    And you can ignore this locale stuff.
  • 5:52
    That's just stuff on my server.
  • 5:54
    But this bottom line here is very important.
  • 5:57
    It's telling me I need to reload my Apache configuration
  • 6:00
    in order for this to take effect.
  • 6:02
    So I've enabled the site vhost but I actually need to reload Apache
  • 6:06
    so Apache will begin using it, in order for it to actually work.
  • 6:09
    So I'm going to go ahead and run this command real quickly.
  • 6:12
    And there we go.
  • 6:13
    So the Apache stuff is taken care of to set this up.
  • 6:17
    We need to test this.
  • 6:18
    Let's go look in a browser and make sure that our domain names are
  • 6:22
    actually hitting this Drupal directory now.
  • 6:25
    So this is udrupal.com.
  • 6:26
    If I go ahead and reload this page, now I
  • 6:29
    get to my installation screen.
  • 6:31
    So perfect, we are actually hitting the Drupal installation.
  • 6:35
    I'm going to go ahead and actually install this first central site.
  • 6:40
    And then, in future tutorials, we'll be looking at how we handle getting
  • 6:44
    the other sites directed to the right place.
  • 6:46
    But I'm going to go ahead and install udrupal.com just so that we
  • 6:50
    have at least our main Drupal site up and running.
  • 6:53
    So I'll run through this installation really quickly here.
  • 7:07
    And now we have our new University of Drupal site at udrupal.com.
  • 7:14
    So we have our Apache configuration set up correctly so that our domain
  • 7:18
    name is pointing to our Drupal code base.
  • 7:21
    And we've been able to go through just regular installation
  • 7:24
    of a regular Drupal site setting up the database.
  • 7:27
    And now we need to figure out how to deal with our other domain names.

Configure Apache for Multiple Domains

Loading...

In this lesson we'll be building a simple university site, udrupal.com, with different areas, each with their own website: the main site, a news site, and an alumni site. The news site is simply a subdomain of the main domain name, news.udrupal.com, and the alumni site actually has its own separate domain name, udrupalalumni.com. To get this done, you're going to learn how to confirm the DNS is working for the domain names. That is, that they are currently pointing to the right server. Then we're going to configure an Apache vhost on our server so that Apache knows where to find our Drupal code base. We'll finish things up by installing our main Drupal site, udrupal.com.

Downloads: 
Log in or sign up to download companion files.
Additional resources: