Create Domain(s), Subdomain(s) as Virtual Host on Ubuntu


Step 1:

Open using gedit editor or as u like…

sudo gedit /etc/hosts

Step 2:

Add lines like this:         localhost

Now save the file.

Step 3:


sudo gedit /etc/apache2/httpd.conf

Add the following peace of code:

NameVirtualHost *:80

     ServerAlias *
     DocumentRoot /home/my_user_dir/www

Save the file and restart apache.

Test using your favorite web browser with your vertual domain link i.e.

To restart apache use the following command
sudo /etc/init.d/apache2 {start | stop | restart | status}


If you want the sites to be available and enabled to the world, look the following directories:


This contains configuration files for sites which are available but not necessarily enabled.


This directory contains site files which are enabled.

Example: (file inside /etc/apache2/sites-enabled/)

<VirtualHost *:80>

     DocumentRoot /home/my_user_dir/www/
     <Directory />
          Options FollowSymLinks
          AllowOverride None
     <Directory /home/my_user_dir/www/>
          Options Indexes FollowSymLinks MultiViews
          AllowOverride None
          Order allow,deny
          allow from all

     ScriptAlias /cgi-bin/ /home/my_user_dir/www/
     <Directory "/usr/lib/cgi-bin">
          AllowOverride None
          Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
          Order allow,deny
          Allow from all

     ErrorLog /home/my_user_dir/www/

     # Possible values include: debug, info, notice, warn, error, crit,
     # alert, emerg.
     LogLevel warn

     CustomLog /home/my_user_dir/www/ combined

     Alias /doc/ "/usr/share/doc/"
     <Directory "/usr/share/doc/">
          Options Indexes MultiViews FollowSymLinks
          AllowOverride None
          Order deny,allow
          Deny from all
          Allow from ::1/128


You need to save the file and restart apache2, for the changes to be reflected.

#sudo /etc/init.d/apache2 restart

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s