Installing Apache 2.4

sudo apt-get install apache2
To create a new virtual host, firstly, you need to create appropriate directories:
sudo mkdir -p /var/www/test.loc/www
sudo mkdir -p /var/www/test.loc/logs
Usage of -p allows the creation of nested directories specified in the path.
Apache comes with a default virtual host called 000-default.conf which it uses by default, but we are going to create a new one - test.loc.conf for our domain test.loc:
sudo nano /etc/apache2/sites-available/test.loc.conf
<VirtualHost *:80>
    ServerName test.loc
    ServerAlias www.test.loc

    DocumentRoot /var/www/test.loc/
    <Directory /var/www/test.loc/>
        AllowOverride All
    </Directory>

    CustomLog  /var/www/test.loc/logs/access.log common
    ErrorLog /var/www/test.loc/logs/error.log
    LogLevel warn
</VirtualHost>