Setup virtualhost for hosting multiple domains

Create a folder at your desired location to host your new domain files

mkdir -p /var/www/

-p helps to create parent directories if they don’t already exist

Edit your hosts file

sudo nano /etc/hosts

Add entry to your hosts file

Create a new.domain.conf file for your new domain site in /etc/apache2/sites-available. I prefer to copy from 000-default.conf

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/NewDomain.conf
sudo nano /etc/apache2/sites-available/Newdomain.conf

Update your configuration

<VirtualHost *:80>
    DocumentRoot /var/www/
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order allow,deny
        allow from all
        Require all granted
    ErrorLog ${APACHELOGDIR}/
    CustomLog ${APACHELOGDIR}/ combined

Enable new domain site in apache with

sudo a2ensite

Restart Apache2

sudo service apache2 restart

Ensure that you have already setup your public DNS pointing to your server.

Leave a Comment

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