Create a New Site with Apache on ubuntu

Suppose you want to serve a new site under the domain In this article , we see how to configure apache to serve the new site.


step 1 - Create a Directory

Create a new directory site and create the following subdirectories inside:

  • public - This directory will contians the actual content of the site the should be served by apache.
  • logs/apache - this directory will contians the generated logs related the site
Directory Structure
 ├──────────────public ├ The site files. For example : index.html, index.php ...
 └──────────────apache ├ apache logs related to the site : error.log , access.log

step 2 - Create VirtualHost

Create a new config file /etc/apache2/sites-available/example.conf

Configuration for

     DocumentRoot "/sites/example/public"
     ErrorLog     "/sites/example/apache/error.log"
     CustomLog    "/sites/example/apache/access.log" combined
     <Directory "/sites/example/public">
         Options Indexes FollowSymLinks Includes ExecCGI
         AllowOverride All
         Require all granted

step 3 - Enabling Site and Resatrt Apache

Enable the site using a2ensite command.

Enabling Site
$ a2ensite example.conf
Enabling site example.
To activate the new configuration, you need to run:
  systemctl reload apache2

As suggested, you should restart apache to activate the new site. Let’s do it:

Restart apache
$ systemctl reload apache2
Software Developer

Kobi helps entrepreneurs to translate their wishes to a working product.