How to Set Up Apache Virtual Hosts on Ubuntu 14.04

Michael Douse
by Atlantic.Net (9posts) under VMware Hosting
0 Comments
Verified and Tested 02/17/15

Introduction

In this article, we will go over how to add additional virtual hosts to a Linux cloud server with Apache installed. Each virtual host handles a specific website or domain that will be hosted on the server, including sub-domains. This is referred to as named-based hosting because it allows multiple websites to utilize one set of resources, such as a single IP.

Prerequisites

This article assumes that you have already installed Apache and performed the basic configuration of it. If you have not done so, follow our how-to on this here.

Setting up Apache Virtual Hosts on Ubuntu 14.04

All sites/hosts are located in the following directory:

/etc/apache2/sites-available/

If you have just installed Apache, these are the only things you should see:

Directory: /etc/apache2/sites-available/

Directory: /etc/apache2/sites-available/

Create a virtual host configuration file using your preferred text editor. In this example, nano is used.

nano /etc/apache2/sites-available/virtualhost.example.conf

Add a basic configuration to this file and save:

Sample Virtual Host configuration

Sample Virtual Host configuration

Some of the sections you may consider changing are:

<VirtualHost *:80>

This is the port that this virtual host will be accessible from. If we were to change 80 to 8080 then we would type the following URL to access the host: http:// virtualhost.example:8080

ServerName virtualhost.example
ServerAlias www.virtualhost.example

These values will indicate the domain that this virtual host will be representing and the alternate name for the host.

ServerAdmin [email protected]

Update this with your applicable server admin email address.

DocumentRoot /var/www/virtualhost.example/public_html

This will be the location of the site files for the specified domain.

Next enable the virtual host with the following command:

a2ensite virtualhost.example.conf

Your output should look like this:

a2ensite sample output

a2ensite sample output

Lastly, just restart Apache as indicated by the prompt

service apache2 reload

Congratulations! You have now successfully Set Up Apache Virtual Hosts on Ubuntu 14.04. Thank you for following along and feel free to check back with us for further updates.

More About Atlantic.Net

Atlantic.Net offers world-class hosting solutions, including VMware hosting services.

Not sure what you need?

Get a free consultation today!

New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources

We use cookies for advertising, social media and analytics purposes. Read about how we use cookies in our updated Privacy Policy. If you continue to use this site, you consent to our use of cookies and our Privacy Policy.