Guide to Setting up Virtual Hosts with Apache

Many times you’ll want to setup an Apache server to host multiple, independent server connections. In these cases, there are a series of simple steps you can follow to setup virtual hosting by adjusting your configuration files. There are a number of scenarios in which this practice may be useful including setting up a hosting company, segmenting server resources and adjusting your IT environment to handle multiple departments. This guide will help you walk through the basic steps of getting Apache setup to run multiple virtual hosts.

Once you have your Apache server initially configured you can update the main configuration files to segment the server into multiple hosts. There are a wide range of reasons why you might want to setup virtual hosts in Apache, and the servers are sufficiently flexible to allow for segmentation of resources. In general, these files will be in the etc/apache folder, although you can find their exact location with a phpinfo query. Files in these folders are write-protected, so you’ll have to update the settings via root in order to properly access them. Make sure you have proper access levels before you attempt to update these settings.

As a first step you’ll need to update your httpd.conf configuration file to add an include command which calls your virtual host (vhost.conf) configuration file. In particular, you should add the following line to the configuration file:

Include /etc/apache2/vhost.d/vhost.conf

Setting up your vhost.conf in the /vhosts.d directory to allow multiple server hosts is the first step toward virtualizing your server.  You can edit this file in order to setup multiple domain hosts on your server, even if they’re connecting to a single IP (or group of IP) addresses. You can do this by creating a virtual host block in your configuration file by identifying the virtual hosts. After identifying the independent server admins on each virtual host, you can setup a root directory for each virtual host and then setup the server alias based upon the domain:

Namevirtualhost serveradmin admin@example.com

DocumentRoot /srv/www/htdocs/directory/

ServerAlias example.com *.example.com

Note the wildcards in the server alias allow each virtual host to setup sub-domains and sub-directories within their domain.  After you update your configuration file properly you can then restart apache in order for the new settings to allow for virtual hosts on your Apache server.  Keep in mind there are multiple types of virtual hosts supported by Apache including domain based hosts, where there is multiple sites on each IP address, and IP-based virtual hosts which allows an IP address for each web site on a server.

These settings can help independent developers setup their own hosting company or update settings for company wide use.  Common applications are setting up multiple domain aliases (CNames) on a single server. This flexibility makes Apache idea for developers and businesses which require the ability to run multiple sites on a server or to setup different hosting environments for clients, projects and data.  Apache servers give you the freedom to properly setup and configure your files as you see fit, so you can utilize your server space accordingly.

0 responses so far ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment




spacer