Apache is very flexible, and it's easy to configure Apache to handle several domains even when your Web server only has one IP address to share between them. You can use this to host multiple sites, or just to provide a sandbox for development rather than making changes on your live site. This weekend, we'll learn how to create virtual hosts with Apache.
Setting up virtual hosts might seem like a big challenge, but it's not. In fact, you can set up a virtual host with just a few edits to Apache's configuration and by setting up additional directories for the documents. For this how to, I want to use an Apache installation on a Ubuntu server. Please be aware, the instructions for this may require modification if being done on a non-Debian distribution because of the way that Apache is packaged. However, the Apache directives should be standard across distributions and should work even if Apache isn't running on Linux.Skipping on down...
If the server hosting the virtual sites is a non-Debian distribution, the steps are different for hosting virtual sites. Here's how it works:
- Create the directory container for the virtual site in
/etc/httpd/conf/httpd.conf. This container will look similar to that used for the Debian-based server.
- Make sure the Apache configuration file is aware of virtual hosts by making sure the line
Include conf.d/*.confis not commented out.
- Create the new virtual hosts file (we'll call it
- Add the virtual site to the
- Restart Apache with the command
The directory container, for the non-Debian host, will look similar to the very basic container below: