How To Install Your Own Web Server - Adding A Virtual Host

June 10th, 2008 · 1 Comment

In my last post of this series, I’ve shown you how to create a MySQL database using the GUI tools. In the fifth part of this tutorial, we’re now going to see how to add a virtual host.

What Is A Virtual Host?

A virtual host allows your web server to serve multiple websites from a unique shared IP address. Apache in this case, knows which website to serve based on the domain name requested by the web browser.

How To Add A Virtual Host

For this tutorial, we’re going to add a virtual host so that we can install phpMyAdmin to manage our MySQL database.

Usually we would install phpMyAdmin in a directory and configure an aliase so that it could be accessed from any website hosted on this web server (ie.: http://www.myfirstwebsite.com/phpmyadmin, http://www.mysecondwebsite.com/phpmyadmin, etc.).

But let’s not go there right now, we don’t want to get confused from the start.

  1. Using Notepad, open C:\Apache2\conf\httpd.conf
  2. At the very end of the file, you’ll see a virtual host configuration example commented out. Copy and paste this section and uncomment it so it looks something like this:
    <VirtualHost *:80>
        ServerAdmin webmaster@dummy-host.example.com
        DocumentRoot /www/docs/dummy-host.example.com
        ServerName dummy-host.example.com
        ErrorLog logs/dummy-host.example.com-error_log
        CustomLog logs/dummy-host.example.com-access_log common
    </VirtualHost>
  3. Now we’re going to edit this virtual host. We want it to be named “phpmyadmin” and we’ll eventually put the files in c:\www\phpmyadmin :
    <VirtualHost *:80>
        ServerAdmin info@thewebhostinghero.com
        DocumentRoot /www/phpmyadmin
        ServerName phpmyadmin
        ErrorLog logs/phpmyadmin-error_log
        CustomLog logs/phpmyadmin-access_log common
    </VirtualHost>
  4. Using Windows Explorer, create a directory named www at the root of your C: drive. In this directory, create a subdirectory named phpmyadmin (ie.: C:\www\phpmyadmin).
  5. We now need to add an entry to our hosts file. The hosts file is a configuration file that tells MS Windows the IP address corresponding to a host name when it cannot be resolved through WINS or DNS. Using Notepad, open C:\[windows directory]\system32\drivers\etc\hosts
  6. Add the following line at the very end of the file:
    127.0.0.1	phpmyadmin

    The IP address 127.0.0.1 is a loopback address which means that it always point to your local computer.

  7. Save your hosts file and close Notepad.
  8. Restart the Apache2 service (Don’t remember how? See step #14 from this post).
  9. Open your web browser to http://phpmyadmin . If everything went correctly, you should see this error page (yes, an error page!):
    Apache Virtual Host Tutorial

The error message is caused by the fact that there’s simply no files in C:\www\phpmyadmin and that Apache has been configured to deny directory browsing. Once we have installed phpMyAdmin, we won’t see this error message again.

Stay tuned as next time we’ll install phpMyAdmin in our virtual host directory.

Click here to subscribe in a RSS reader or by email to receive updates.

1 response so far ↓

1. Response by : How To Install Your Own Web Server - Installing phpMyAdmin on Jun 12, 2008 at 1:28 pm

[...] Extract the content from the archive to your hard drive in C:wwwphpmyadmin (if you followed this tutorial). [...]

Leave a Comment




Posted in Apache · MySQL · PHP · Tutorials · Windows Server | 1 Comment

Dedicated Servers
 
VPS
Website Hosting
 

Recent Comments

Recent Webmasters

Hosting Type :
Monthly Price :
Storage :
Transfer :
Sort By :