How to create Virtual Hosts PHP | Apache ?

Focus

Web Developer should have a requirement to work on various environment . Some projects are in plain php, some are in Framework like CodeIgniter, Symfony .. These all need different configuration and sometime need to use htaccess mode rewrite etc.

Those need to be in root folder.

We can access each  project like

http://accommodationcheap.oi

http://iwordzo.oi

http://helloplot.oi

simultaneously without altering any configurations each time we use. So different htaccess can run simultaneously with the hostname.

How can i add Virtual Host and Virtual Directory ?

  1. Search for “hosts” in your system folder

Creating Virtual Hosts

2. Edit this file using notepad

Add the following lines

127.0.0.1    localhost
::1                   localhost
127.0.0.1   wordzo.oi
127.0.0.1   accommodationcheap.oi
127.0.0.1   helloplot.oi

Description

127.0.0.1 This is  the default ip address of local host

Ip address followed by domain name you want to use

you can add google.com as domain name and when u type google.com on your browser it will show your local site. It wont display actual google site .

For the development purpose i have added .oi extension. You can use your own extension.

3. open you httpd.conf located at apache folder with notepad or any other simple text editor

Append this code to your httpd.conf


#Virtual Host Directory Settings for wordzo

NameVirtualHost wordzo.oi:80

<VirtualHost wordzo.oi:80>
DocumentRoot E:/Project/iwordzo
ServerName wordzo.oi

# Other directives here

</VirtualHost>

#Vitual Directory Settings for Accommodationcheap.in

NameVirtualHost accommodationcheap.oi:80

<VirtualHost accommodationcheap.oi:80>
DocumentRoot E:/Project/accommodationcheap
ServerName accommodationcheap.oi

# Other directives here

</VirtualHost>

#Virtual Directory Settings for Helloplot.com

NameVirtualHost helloplot.oi:80

<VirtualHost helloplot.oi:80>
DocumentRoot E:/Project/helloplot
ServerName helloplot.oi

# Other directives here

</VirtualHost>

4. Restart your apache

5. That’s it 🙂

You can browse your localhost sites using

http://accommodationcheap.oi

http://iwordzo.oi

http://helloplot.oi

Note: These settings are for Windows machine

Reference Links

http://httpd.apache.org/docs/1.3/vhosts/name-based.html

About

me : yeay its me arun

Tagged with: , , , , , , ,
One comment on “How to create Virtual Hosts PHP | Apache ?
  1. BINISH says:

    Its a good post, helped me to configure Apache in Solaris. Thanks Arun

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.