Create Virtual Host Files In Ubuntu

Tamrakar Shreyaa
1 min readJul 18, 2021

--

Apache comes with a default virtual host file called 000-default.conf that we’ll use as a template. We’ll copy it over to create a virtual host file for each of our domains.

Create the First Virtual Host File

Start by your the first domain

sudo cp /etc/apache2/sites-available/test.conf

Open the new file in your editor (we’re using nano below)

sudo nano /etc/apache2/sites-available/test.conf

We will customize this file for our domain. Modify the ServerName,DocumentRoot

<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName test.local.com
ServerAlias www.example.com
DocumentRoot /var/www/html/test/public

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "D:/xampp/htdocs/genealogy">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Enable the New Virtual Host Files

sudo a2ensite test.conf

Next, disable the default site defined in 000-default.conf

sudo a2dissite 000-default.conf

When you are finished, you need to restart Apache

sudo systemctl restart apache2

Setting Up Local Hosts File

sudo nano /etc/hosts
127.0.0.1   localhost
127.0.1.1 guest-desktop
your_server_IP your_domain_1
your_server_IP your_domain_2

--

--

Tamrakar Shreyaa
Tamrakar Shreyaa

Written by Tamrakar Shreyaa

Laravel | PHP | Node| nestjs |API | AJAX | jQuery | Laravel vue | Livewire | LAMP stack | CI CD

No responses yet