How to setup apache virtual hosts on ubuntu (Easy Way)

How To Create Apache VirtualHost in Ubuntu

vhost


Set up Apache virtual hosts on Ubuntu is very easy. Please follow this steps.

In this tutorial, we show how to setup virtual hosts in Apache web server on Ubuntu.

First enter in root mode.
ibrar@ansari:~$sudo –i

1. Copy the 000-default.conf file:
root@ansari:~#cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/mydomain.com.conf

2. Open your newly copied config file.
root@ansari:~#nano  /etc/apache2/sites-available/mydomain.com.conf

3. In the file, find DocumentRoot towards the beginning of the file, and update with. your own domain:
DocumentRoot /var/www/html/mydomain.com

4. Below DocumentRoot, add these two lines:
ServerName mydomain.com
ServerAlias www. mydomain.com

5. Enable your virtual host.
root@ansari:~# a2ensite mydomain.com.conf

6. Restart Apache Server :
root@ansari:~#service apache2 restart

7. Get a list of all virtual hosts which are defined in all apache configuration files Served by Apache2.
apache2ctl -S

8. View log.
ls /var/log/apache2/
or
ls /var/log/apache2/error- mydomain.com.log


Removing a Virtual Host.
root@ansari:~#rm /etc/apache2/sites-available/ mydomain.com conf
root@ansari:~#rm /etc/apache2/sites-enabled/ mydomain.com.conf


SHARE

Ibrar Ansari

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment