How to create a virtual host

There are two ways you can create your virtual hosts easily.

  1. Through command prompt using ssh
    • If you have already installed the vagrant box, then open your bash command window or putty type
      vagrant up 
      

      this will start the virtual machine

      vagrant ssh 
      

      To ssh to the vm and finally

      sudo nano /etc/httpd/con/httpd.conf
      

      to edit the Apache config file
      Check the image here.
      Vagrant output

    • scroll down to end of the file and type
      DocumentRoot /home/vagrant/public_html/sampleproject
      ServerName sampleproject.local
      <Directory  /home/vagrant/public_html/test>
      AllowOverride All
      </Directory>
      ErrorLog /home/vagrant/public_html/logs/sampleproject_error_log
      CustomLog /home/vagrant/public_html/logs/sampleproject_access_log common
      
      
    • Now press CTRL+O to save the file
    • now restart the apache by typing sudo service httpd restart
    • Time to configure our sampleproject.local domain in our OS. To do that open your hosts file and add
      127.0.0.1 sampleproject.local
    • Save the hosts file and open a browser and browse sampleproject.local:8000
  2. Through webmin/virtualmin (it is a gui interface)
    • Log in to webmin by browsing https://localhost:10080/
    • Use username as root and password as vagrant
      webmin1
    • After login you will see the home page of webmin
      webmin2
    • Under left navigation open Server->Apache Webserver
    • Now create a virtual host. Check the image below
      webmin4
    • Select “Any Adress” for Handel Connetions to address
    • Use Port:80
    • Select DocumentRoot
    • Write ServerName (in our case it is sampleproject.local
    • Click the “Create Now” button to create your virtual hosts
    • Now configure our sampleproject.local domain in our OS. To do that open your hosts file and add
      127.0.0.1 sampleproject.local
    • Save the hosts file and open a browser and browse sampleproject.local:8000

That’s it. Let me know if you have any problem.

0

About the author

Janaki(http://mjanaki.com) - A Software developer with 9+ years of experience in multiple technology projects across web, mobile, and cloud applications with expertise in PHP, C#, MySQL, Web services and open source platforms.

Similar Posts

IIS redirect
Custom error page in Laravel

Comments are closed.