Steps to create a virtual host in apache2 using default configuration file. Considering you are using Ubuntu OS. Lets setup example.dev on your apache server.
Step 1.
Switch to directory /etc/apache2/sites-available/.
1 2 | #Open 000-default.conf using nano editor sudo nano 000-default.conf |
Step 2:
Append the following code in the file (replace example.dev with your desired domain / hostname )
1 2 3 4 5 6 | <VirtualHost *:80> DocumentRoot "/var/www/example.dev/public_html/" ServerAdmin admin@yourdomain.com ServerName example.dev ServerAlias www.example.dev </VirtualHost> |
Step 3:
Enable new configuration and restart apache server
1 2 3 4 5 | #Enable new site/host sudo a2ensite 000-default.conf #Now restart Apache sudo service apache2 restart |
Thats all, you have done ๐ .