Israel Science and Technology Directory

InternetApache server

Configuring Apache2 server on Ubuntu

The installation of Apache2 server together with PHP was decribed on another page entitled Installing Apache2 and PHP.

This page decribes configuration of Apache2 server definitions. All the instructions should be executed in a terminal window by a user that has sudo authorization.

The text editor that is used here is nano.

1. Define the default location of the website for your Apache2 server

In the Apache2 server, the default directory of the website is /var/www/html as specified by the line:

DocumentRoot /var/www/html
This means that all the website content will be located in the directory named "html", and the opening page of the website will be the default page for the directory, e.g., index.html.

If you prefer to use your domain name (example: example.com) instead of "html" you can change this location, by editing the Apache configuration file.

DocumentRoot /var/www/example.com

If you choose this option then you have to create a new directory using the following command:

sudo mkdir /var/www/example.com

2. Default file name to be loaded when a directory name is entered.

In order to prevent the listing of the contents of a directory, it is recommended to specify a default file name that will be opened when the directory is called. For this purpose edit Apache configuration file .htaccess.

To specify the default file name(s) to load for a directory, add the following line. For the example below, the default file that will be loaded will have the name of either default.php or index.html in this order of priority.

DirectoryIndex default.php index.html