Overview
Domain name or Host name is used for virtual host in a computer. It can give a specific domain name to your website on localhost or a direct route to your specific folder containing website on localhost. By this, you can access every web folder with specific domain name.
We need to set vhosts(Virtual Hosts) in configuration folder of <u>Apache2</u>.
Need help with Linux?
Get a free strategy session with our experts — no commitment required.
Go to the directory: /etc/apache2/sites-available
For every vhost you will have to make a configuration file in this directory. In the vhost configuration you can set your document root. The name of the file must end with .conf
E.g.: /etc/apache2/sites-available/mysite1.conf
Where "mysite1.conf" is the name of file. You can change "mysite1" to your desired name.
Open it in editable mode. And copy the following lines into the file and save.
**<VirtualHost *:80>**
ServerName anything.local
Key steps and notes
DocumentRoot “/var/www/html/yousite1
</VirtualHost>
In these lines, "anything.local" is the domain name that you want to set for site in folder /var/www/html/yousite1. "yoursite1" is the name of folder that you want to access using your domain name.
Now enable your site with:
sudo a2ensite mysite1.conf
And now restart Apache2 to get it working.
Command: service apache2 restart
Then edit your /etc/hosts file.
Just paste the following line on the end:
Final notes
127.0.0.1 anything.local
Now you can access your site with http://anything.local



