Apache + Virtual Hosts

1- Install apache

$ sudo apt-get install apache2

2- Place your project folder under /var/www/html/

Ex: /var/www/html/my-project-folder

3- We need to change the ownership to the regular user. To do so, run:

$ sudo chown -R $USER:$USER /var/www/html/my-project-folder

4- Next, set read permissions to the Apache root directory, using command:

$ sudo chmod -R 755 /var/www/html/

5- Create configuration file for each host

$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/my-custom-domain.loc.conf

Make sure the configuration file end with .conf extension at the end, otherwise it will not work.

6- Edit /etc/apache2/sites-available/my-custom-domain.loc.conf

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName www.my-custom-domain.loc
    ServerAlias my-custom-domain.loc    
    DocumentRoot /var/www/html/my-project-folder

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory />
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
        Allow from all
    </Directory>

</VirtualHost>

7- Enable virtual host configuration files

$ sudo a2ensite my-custom-domain.loc.conf

8- Add to /etc/hosts

127.0.0.1   www.my-custom-domain.loc my-custom-domain.loc

9- Restart apache

systemctl restart apache2

TROUBLESHOOTING

I found myself in the scenario that I might not be able to access to url-subfolders (i.e. http://www.mydomain.com/whatever-url)

I gave solution following the next steps:

1- Add to apache2.conf:

<Directory /var/www/html/<your-site-folder>/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    Allow from all
</Directory>

2- Enable mod_rewrite

$ sudo a2enmod rewrite

Enabling module rewrite.
To activate the new configuration, you need to run:
systemctl restart apache2

3- And restart apache

systemctl restart apache2