Lasso Soft Inc. > Home

  • Articles

Testing Web Applications Locally

Introduction

If you're like me, then you would be using one machine (in my case, a Powerbook G4) to edit your code, run Apache and Lasso and test your sites in a variety of web browsers.

Setting up Virtual Hosts

The first problem you will come across is Virtual Hosts, which is invariably something you would use on your web server. You can use Virtual Hosts just as effectively on your local, standalone machine by editing the apache configuration file and the hosts file. It is outside the scope of this article to explain how to set up Virtual Hosts in Apache, but let's begin by saying that your local Virtual Hosts should point to domains that don't actually exist on the "real Internet". For convenience sake, I create Virtual Hosts on my local system by simply replacing the top-level domain part (such as ''.com'' or ''.ie'') with ''.local''.

If you want to make sure that you can test more than one site effectively from a Windows PC (see below), you need to make sure that your httpd.conf file contains the following line:

  NameVirtualHost *

Now, to test an application which will ultimately live at www.mydomain.com I would set up a Virtual Hosts for www.mydomain.local:

<VirtualHost *>
      DocumentRoot "/Library/WebServer/Documents/mydomain"
      ServerName www.mydomain.local
</VirtualHost>

 

Editing the Hosts File

Now the trick is to get the browser on your machine to retrieve your local application without trying to look for it on the Internet. To that end you will need to edit the hosts file - using the terminal and authorising as root:

sudo vi /private/etc/hosts

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

 

Above you can see the typical contents of the hosts file - we are going to ignore the warning that you should "not change this this entry" :-)

Taking our example, we add the following line at the end of our hosts file:

  127.0.0.1 www.mydomain.local

Save and exit the hosts file, and test in your browser. If all is well, you should now be able to access your local application through your fake domain.

Using Webmin

All of the above tasks can be performed a lot easier if you install Webmin. This handy Perl application allows you to edit lots of stuff that you would normally access from the Terminal by using a web browser. This includes the Apache configuration file ''httpd.conf'' (under Webmin module "Servers") as well as ''/private/etc/hosts'' (Webmin module "Networking > Network Configuration").

Testing from a PC on your LAN

The next very common problem, is that you will need to test your application on behalf of those underprivileged people who are forced to use a Windows PC :-|

Instead of installing Virtual PC, I use a "real" one - a cheap Dell on my local network. To force this machine to look for www.mydomain.local on my own machine instead of surfing the net, we apply the same trick as we did locally: edit the ''hosts'' file, but this time on the PC, and using a different entry. The ''hosts'' file on a Windows machine can be found here:

  C:\WINDOWS\system32\drivers\etc\hosts

You can simply edit this file with ''Notepad''. I placed an alias, I mean shortcut, on my PC desktop for easy access. To point the PC in the direction of my local Mac, I first need to find out my Mac's LAN IP address - let's say it's 192.168.1.33. I then need to add the following line to my PC's hosts file:

  192.168.1.33 www.mydomain.local

If everything went according to plan, you should now be able to access the VirtualHost site running on your Mac from your PC, so you can see how IE makes a mess of your lovingly crafted CSS, etc...

Author: Pier Kuipers
Created: 11 Sep 2008
Last Modified: 16 Mar 2011

Comments

No comments found
You must be logged in to comment.

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft