e Learning

How to Install Apache on Ubuntu Server 14.04

Apache2 is the most popular Web Server Implementation for Ubuntu Server 14.04. In This Tutorial we are going to learn how to install Apache on Ubuntu Server 14.04. In Addition to installing Apache on Ubuntu Linux, we will also learn how to create and configure Apache Virtual Host and host a simple static website on Ubuntu Server.

Install Apache on Ubuntu 14.04

Apache web server for Ubuntu Linux provides by the apache2 package. We can install Apache2 on Ubuntu using apt-get install command.

sudo apt-get update

sudo apt-get install apache2

Then start the Apache web server using service command.

sudo service apache2 start

Now if you type your server IP address on the web browser you should get the Ubuntu Apache2 default web page.

Install Apache on Ubuntu Server 14.04

Configure Apache Virtual Host in Ubuntu Linux 14.04

So now let’s see how to host a static website on Ubuntu Apache Server. For this tutorial I am going to use the domain name www.example.com. And I am going to host www.example.com in /var/www/example folder.

Step One

Create the Document root

First, create the folder /var/www/example using the mkdir command.

sudo mkdir /var/www/example

Then we need to make apache group www-data as the group owner of the /var/www/example folder and also give write permission to the group.

sudo chgrp www-data /var/www/example/

sudo chmod g+rwX /var/www/example/

sudo chmod g+s /var/www/example/

Step Two

Create the Virtual Host

We configured document root for the our domain name www.example.com, now we need to create the apache virtualhost for the www.example.con domain.

Ubuntu Apache Virtual Host Configuration file should be create inside the /var/www/site-availe directory using .cong extension.

touch /etc/apache2/sites-available/example.conf

Now open example.conf file we created, using a text editor and add the following virtual host configuration.

<VirtualHost *:80>

ServerName www.example.com

ServerAlias example.com

DocumentRoot /var/www/example/

ErrorLog /var/log/apache2/example.com.error

CustomLog /var/log/apache2/example.com.access combined

</VirtualHost>

Step Three

Enable the virtual host

Now we need to enable the virtual host using a2ensite command. Then restart the apache server using service command.

sudo a2ensite example.conf

sudo service apache2 restart

a2ensite enable ubuntu apache virtual host

Ok, now we have configured the apache virtual host for our domain name www.example.com. Now all we have to do is put content of the Website to /var/www/example folder and point www.example.com to our server IP address using DNS.

Just like that you can create as many virtual hosts as you want and host multiple website on your Ubuntu server.

What we Learned ?

In this tutorial learned how to install and configure a basic Web server on Ubuntu Linux 14.04 using Apache Web Server.

First, we Installed Apache on Ubuntu 14.04 using apt-get install command. Then we learned to configure Apache Virtual Host on Ubuntu Linux to host multiple Web sites.