About Me Blogroll Portfolio Estudyante.Me

Setting Up Virtual Host for XAMPP

November 26, 2011 by | No Comments

If you had installed Zend Framework on your local for your project and  followed their Quickstart Guide, I’m sure you had encountered adding a Virtual Host. Yes, we’re on the same page. I also had successfully installed Zend Framework on my local and it really does worked. Typing http://zend.localhost is easier and convenient than http://localhost/zend/public, isn’t it? But when I visit phpMyAdmin to create Zend installation. I tried to access all my other program in my localhost, it always ended me up to Zend. Dang! That made me scratched my head and had a big WHY? I am not so good at Apache and all other server stuff so I used my DOH (Department of Help). Googling. Googling again. Then asked a friend and tadaAa!!! Finally got it. =)

To create your vhost, follow the steps below. I am assuming that you are using XAMPP.

Locate your httpd.conf

You can find it in C:\xampp\apache\conf\ directory. Within your httpd.conf (or httpd-vhosts.conf on some systems and can be found in extra\ directory), you will need to do two things.

First, ensure that the NameVirtualHost is defined; typically, you will set it to a value of “*:80″.

NameVirtualHost *:80

This line turn on the Virtual Host feature on Apache.

Second, define a virtual host:

<VirtualHost *:80>
    DocumentRoot "C:\xampp\htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:\xampp\htdocs\zend"
    ServerName zend.localhost
  <Directory "C:\xampp\htdocs\zend">
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

The first four lines of code set up the C:\xampp\htdocs folder as the default location for http://localhost. This is what I missed when during my initial installation before. This is important since you need to be able to access the XAMPP web pages at http://localhost/ so that you can use PHPMyAdmin.

DocumentRoot

- indicates where the files for this site are located on your computer

ServerName

— is the name of your virtual host

<Directory>

— is the same path you provided for the DocumentRoot. This is required to let your Web browser have clearance to access these files.

Edit hosts file

Go to C:\windows\system32\drivers\etc\.  Open it using Notepad run as Administrator to have permission to edit and save this file. At the end of the file, add “127.0.0.1      zend.localhost“.

Restart Apache

Using your xampp-control, restart Apache. Open a browser and launch your site using your virtual host. You should see now the homepage of your site.

If I missed something here, just message me on the comments below and let’s talk about it. Thanks! =)