widgets Add Virtual Host on Apache


We have installed apache2 and Ubuntu server on our virtual machine. Now let’s define a new domain.

Go to /etc/apache2/sites-available and look the directory. There is a file named 000-default.conf copy and rename with the full domain name with .conf


cp 000-default.conf newdomainname.com.conf

Then open the file with the editor. Add the required information to the file.

ServerAdmin info@extra.codes
ServerName newdomainname.com
ServerAlias newdomainname.com
DocumentRoot /var/www/virtualsites/newdomainname.com/public_html
<Directory "/var/www/virtualsites/newdomainname.com/public_html">
    AllowOverride All
</Directory>

Create a directory:


mkdir -p /var/www/virtualsites/newdomainname.com/public_html

Give a permissions:


sudo chmod -R 755 /var/www/virtualsites/newdomainname.com
sudo chown -R www-data /var/www/virtualsites/newdomainname.com

Last part activate the site:


a2ensite newdomainname.com

Reload the apache service


systemctl reload apache2

Done. The virtual host is ready for use. you can test it by creating an index.html file inside the public_html folder. And also it’s possible to create many virtual hosts with this way.