Installing and Configuring the Apache2 Web Server

Apache HTTP Server – named after the tribes of the North American Indians of Apache, is also an abbreviation of “a patchy server” – a free web server.

An example of an installation command in Ubuntu:

sudo apt-get install apache2

Example installation in CentOS:

sudo yum install httpd

We check to open in the browser the address http://HOSTNAME
Normally, a standard inscription should appear “It works!“.

Web Storage Directory – /var/www/
Directory of configuration files – /etc/apache2/

A separate virtual host is created for each site. The standard virtual host file is located at /etc/apache2/sites-available/000-default.conf

Suppose we have an domain. Create a new file in the /etc/apache2/sites-available/example.conf and prescribe the settings in it:

<VirtualHost *:80>
     DocumentRoot /var/www/
     <Directory /var/www/>
     Options -Indexes
     AllowOverride All
     Order allow,deny
     allow from all
     #You can restrict IP access to some directories, for example, the admin panel in this way:
     <Directory /var/www/>
     Order allow,deny
     allow from
     ErrorLog /var/log/
     CustomLog /var/log/ combined

I’ll describe the options I mentioned above:
-Indexes – in the absence of index files index.php, index.html, etc. the contents of the directories will not be displayed.
FollowSymLinks – allows you to navigate through symbolic links.
-MultiViews – if you specify an example of a non-existent directory the inclusion of this directive will allow you to redirect to the file or etc . if any one of them exists, such manipulations can badly affect the indexing of links by search engines, so it is better to disable this directive.
AllowOverride All – allows the use of additional configuration files. htaccess.

Next, make a link to this file in the directory /etc/apache2/sites-enabled/. You can do this with commands (the second one to delete, ending .conf is not specified):

sudo a2ensite
sudo a2dissite

Check if the configuration is correct:

sudo apachectl -t

If you need to activate any modules, you can also do this by eg commands (the first command to enable, the second to disable):

sudo a2enmod rewrite
sudo a2dismod rewrite

To activate additional configuration files:

sudo a2enconf TEXT
sudo a2disconf TEXT

Now create a directory for the site and copy the files into it:

sudo mkdir /var/www/

In the /etc/apache2/conf.d/security file, we’ll change some of the web server security settings:

ServerTokens Prod
ServerSignature Off

Restart Apache2 for the changes to take effect:

sudo /etc/init.d/apache2 restart
sudo service apache2 restart

If the server uses many IP addresses, and apache2 should not work at all, then you can specify in which it works in /etc/apche2/ports.conf, you can also change the port, for example:


To work at all:

Listen 80

An example of disabling/enabling Apache2 autorun at operating system startup (Ubuntu):

systemctl is-enabled apache2
systemctl disable apache2
systemctl enable apache2

View apache2 version:

apache2 -v

See also my articles:
Access Control Apache2
Installing Certbot in Ubuntu
Redirecting requests to SSL
Installing and Configuring Nginx

Leave a comment

Leave a Reply