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:

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 TEXT
sudo a2dissite TEXT

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/

Let’s edit some web server security settings:
sudo nano /etc/apache2/conf.d/security

ServerTokens OS
ServerTokens Prod

ServerSignature On
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

See also:
Access Control Apache2
Installing and Configuring Nginx

Подписаться на IT Blog (RU) по Email
Subscribe to IT Blog (EN) by Email

Did my article help you? How about buying me a cup of coffee as an encouragement? Buy me a coffe.

Leave a Reply