Project

General

Profile

Apache2 configuration

@date - 15/06/2017 by guanji with instruction of Hervé

A- Introduction

The Apache web server is the most popular way of serving web content on the internet. Apache breaks its functionality and components into individual units that can be customized and configured independently. The basic unit that describes an individual site or domain is called a virtual host.

B- Prerequisites

We need to have Apache installed:

% sudo apt-get install apache2

The Apache File Hierarchy in Ubuntu

What is the use of these configuration files?
  1. apache2.conf: This is the main configuration file for the server. Almost all configuration can be done from within this file, although it is recommended to use separate, designated files for simplicity. This file will configure defaults and be the central point of access for the server to read configuration details.
  2. ports.conf: This file is used to specify the ports that virtual hosts we should listen on. In IAS, for idoc-medoc (-test), we use the default number - 80.
  3. conf.d/: This directory is used for controlling specific aspects of the Apache configuration. For example, it is often used to define SSL configuration and default security choices.
  4. sites-available/: This directory contains all of the virtual host files that define different websites. These will establish which content gets served for which requests. These are available configurations, not active configurations.
  5. sites-enabled/: This directory establishes which virtual host definitions are actually being used. Usually, this directory consists of symbolic links to files defined in the "sites-available" directory.
  6. mods-[enabled,available]/: These directories are similar in function to the sites directories, but they define modules that can be optionally loaded instead.

C- Basic settings

1. Configure a new virtual host or site:

the DocumentRoot directive specifies where Apache2 should look for the files that make up the site. The default value is /var/www/Html, as specified in /etc/apache2/sites-available/000-default.conf. If desired, change this value in our site's virtual host file, and remember to create that directory if necessary!

C-1.1 Copy default conf file to the same directory with our choice:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/ias_new_site.conf

C-1.2 Examples:

default 000-default.conf:

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

IAS idoc-medoc-test conf (There is only one instance for the server name):

        ServerName idoc-medoc-test.ias.u-psud.fr

        ProxyRequests Off
        ProxyPass / http://localhost:8184/
        ProxyPassReverse / http://localhost:8184/

D- Enabling Sites and Modules in Apache

1. To automatically create a symbolic link in the "sites-enabled" directory to an existing file in the "sites-available" directory, issue the following command:

sudo a2ensite virtual_host_file_name

2. After enabling a site, execute the following command to tell Apache to re-read its configuration files, allowing the change to propagate:

sudo systemctl restart apache2.service

E- Apache2ctl

1. Check the syntax - optional:

sudo apachectl -t

2. What is apache2ctl?

E- 2.1 apache2ctl - Apache HTTP server control interface

E- 2.2 apache2ctl is a front end to the Apache HyperText Transfer Protocol (HTTP) server. It is designed to help the administrator control the functioning of the Apache apache2 daemon.