Linux – Apache Part 1: Instalation and configuration

Our own www server is sometimes needed when building webapp, it is also used in internal like in external networks.

Here is as simple recipe for it:

#set proper hostname
hostnamectl set-hostname nasz_hostname

vim /etc/hosts
#add this line to file
ip.address hostname.domain hostname

apt-get install apache2 apache2-doc apache2-utils

#disable default vhost
a2dissite 000-default.conf

#create your own vhost conf
vim /etc/apache2/sites-available/example.com.conf
<VirtualHost *:80> 
     ServerAdmin webmaster@example.com
     ServerName example.com
     ServerAlias www.example.com
     DocumentRoot /var/www/example.com/public_html/
     ErrorLog /var/www/example.com/logs/error.log 
     CustomLog /var/www/example.com/logs/access.log combined
</VirtualHost>

mkdir -p /var/www/example.net/public_html
mkdir /var/www/example.net/logs
a2ensite example.com.conf
service apache2 reload

This configuration is proper for local use.

But if your server will be available outside your network then make those also:

vim /etc/apache2/conf-enabled/security.conf
#disable server signature
ServerSignature Off
ServerTokens Prod
vim /etc/apache2/apache2.conf
#disable directory listing and symlinks
<Directory /var/www/>
        #Options Indexes FollowSymLinks
        Options -Indexes
        AllowOverride All
        Require all granted
</Directory>
#add security module
apt-get install libapache2-modsecurity
/etc/init.d/apache2 restart

#remamber that you need to proper configure security module, which is not covered here

Next parts:

Linux – Apache Part 2: Enable SSL

Linux – Apache Part 3: PHP

Linux – Apache Part 4: MySQL and MariaDB Database

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*