Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

Configure Apache for Multiple Domains

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

Video Details

Duration: 7 minutes and 37 seconds
Country: United States
Language: English
License: All rights reserved
Genre: None
Views: 24
Posted by: drupalizeme on Feb 5, 2015

Configure Apache for Multiple Domains

Caption and Translate

    Sign In/Register for Dotsub to translate this video.