Select Page

Basic Apache Configuration On Ubuntu 18.04LTS

Basic Apache Configuration On Ubuntu 18.04LTS


Apache is the most popular web server running the internet right now.  With 60% to 70% of all web servers running on top of Apache that’s a pretty good vote of confidence in its capabilities and its stability.

If you want to know how to install Apache, take a look at the post Installing LAMP with MySQL or MariaDB on Ubuntu 18.04 which covers installing Apache as part of the LAMP stack.

There are lots of configuration options for Apache, but in this post we’re just going to look at configuring a basic website.

We are going to configure Apache for our website which we have called

The Basics

Whilst there are a few configuration files associated with Apache, we’re just going to be using the basic website config file.

Before we get into the nitty gritty – lets create a directory (folder) for our web site.

To change to the default directory where websites are stored:

> cd /var/www

Then to take a peek at what’s inside:

> ll


The html/ folder stores the default holding page for Apache.  We’ll leave this alone and create a new directory.

> sudo mkdir myownwebsite

Where myownwebsite is the name of your website.

Now let’s go to the directory where the configuration files are stored and take a look around.

> cd /etc/apache2/sites-available

Now lets look at the directory.

> ll


If your server and Apache are newly installed the above is what you’ll see.

The two files named 000-default.conf and default-ssl.conf are used to define the settings for a website.

  • 000-default.conf is for HTTP sites.
  • default-ssl.conf is for HTTPS sites.

These are the default files, so we don’t want to change these, we want to copy them.

> sudo cp 000-default.conf  myownwebsite.conf

Where myownwebsite is the name of your website.

We’re not going to look at the SSL part in this post, we’ll look at that in a following post as there is a bit more to do when using SSL.

Editing the Config File

Now we need to edit the configuration file.

Using your favourite editor bring up the copied file so :

> sudo nano myownwebsite.conf

or my favourite editor

> sudo vi myownwebsite

If you haven’t used vi before you may be better sticking with nano.


OK – so that looks complicated?  It isn’t really.  You just need to know what the bits mean – and most of it is comments anyway

  • VirtualHost *:80 is telling Apache to look for incoming connections on any IP address (*) on port 80 (HTTP).
  • ServerAdmin is the email address of the – er – server administrator.
  • DocumentRoot is the directory where your website is / will be stored.
  • ErrorLog is the location and name of the errorlog.
  • CustomLog is the location and name of the access log – i.e. all requests processed by the server.
  • ${APACHE_LOG_DIR} defines where the default log directory is, and thereby tells Apache to store all logs under this directory.  By default this is /var/log/apache2 so:

${APACHE_LOG_DIR}/error.log = /var/log/apache2/error.log

The first thing we need to do is to change the DocumentRoot to point to our web directory – which we created using mkdir under /var/www/myownwebsite.  So after your change it should look like this:


Remembering of course myownwebsite should be the name of your website.  You’ve got that now haven’t you?  I’m not going to mention that again!

To allow us to host multiple websites on one server we then need to tell Apache the domain name we are going to use, e.g.

Edit the file,  create a new line and add : Servername


You may also want to allow to be used.  To add additional domain names to your website, use the ServerAlias directive, e.g. Serveralias


Now we want to edit the log file names so that when we’re running multiple websites on our server, the logs don’t all get mixed up in one big file.  You don’t have to do this but it makes things easier if you’re running multiple sites.

Edit the configuration file so that the logfile names are unique to our website.


Now save the file and exit back to the command line.

Enabling / Disabling Your Website

Now that all the hard work is done, we need to enable our website:

> sudo a2ensite myownswebsite.conf

With our website enabled we need to tell Apache to reload the config changes.

> sudo service apache2 reload

If for any reason you need to stop your website:

> sudo a2dissite myownwebsite.conf

and then reload the changes:

> sudo service apache2 reload

Leave a reply