Test server. This Setting up a local test server article details how to have a local server to test web applications!  

Articles > Guest Articles > Setting up a local test server

Setting up a local test server

| by John Collins

When designing a web application, as opposed to a web site, you will need to take the jump from client-side technologies like DHTML, to server-side technologies like PHP and Perl. In order to successfully develop in any language, you must posses the ability to test your work before you launch it into the public domain of the Internet. This can be problematic, however, if your web site is hosted remotely by a hosting company, were you need to upload your work to their web server before you can test it. This can be a time-consuming process.

In this article, I will show you how easy it is to set up your own web server on your local PC, using freely downloadable software. The combination we will be working with is:

1. Windows 2000 (any other OS should work fine).
2. Apache 2, as our actually web server.
3. PHP, as our server-side scripting language of choice (Perl is also excellent).
4. MySQL, as our database engine.

In order to understand the relationship of these various technologies and how they fit together, examine the following diagram.

Central to the configuration is the web sever, in this case Apache (we could also use IIS on Windows systems). The MySQL database is also hosted on the server, so all transactions to and from the database will be carried out by the server. PHP is going to be our server scripting language, and this will also be executed on the server. The client-side technologies such as HTML and JavaScript are carried out by a web browser, such as Internet Explorer, so a server is not required to design and test this technologies, only a browser application.

This is the traditional model of a client/web server relationship, in our instance the server and the client are in fact the same computer, so all processing is carried out locally. As you can see, the majority of work on a true web application is carried out at the server level; the browser client is really only an interface between you the user and the server for input and output.

An introduction to Apache

The Apache HTTP server has been the most popular web server on the Internet since 1996. To quote Apache.org "The July 2003 Netcraft Web Server Survey found that 63% of the web sites on the Internet are using Apache, thus making it more widely used than all other web servers combined". As Apache is the central component of our test server, it is important to install it first, as PHP and MySQL will configure themselves for this server when they are installed on your system.

Installing Apache under Windows

You can download the Apache installer from http://httpd.apache.org/download.cgi. Once you have it downloaded, double-click the file to begin the installation, and follow these simple steps:

1. Read the user agreement and accept it.
2. Choose the standard configuration.
3. Enter localhost for the network domain and server name, and any valid e-mail address, as in the screen below.

4. Ensure that on port 80 as a service is selected.
5. Install the typical version.

An introduction to PHP

PHP (PHP Hypertext Preprocessor) is an open source server-side scripting language that is widely used on both Unix and Windows based web servers. The name is a recursive acronym in the same style as GNU, which stands for GNU's Not Unix and which began this unsual trend. Deriving it's syntax from C, Java and Perl, any previous exposure to any of these languages will make PHP easy for you to learn, although no experience is required as there is lots of help to be found online for this popular language. Of course it is up to you to decide on which scripting language to use, for example you could also use Perl or ASP (although the later requires an IIS server), but as I wrote this web site in PHP and many others, I am a bit biased because of it's ease-of-use.

Installing PHP under Windows

You can download the PHP installer from http://www.php.net/downloads.php. Once you have it downloaded, double-click the file to begin the installation.

1. Read the user agreement and accept it.
2. Choose the standard configuration.
3. As with Apache, enter localhost for the server name, and any valid e-mail address.
4. Choose Apache as your server, as in the screen below.

An introduction to MySQL

The MySQL database server is the world's most popular open source database, for both Unix and Windows based systems. It's architecture makes it extremely fast and easy to customize. The minimalistic approach by the developers of the software has resulted in a database management system unmatched in speed, compactness, stability and ease of deployment. The PHP/MySQL combination has become a very common environment to develop fast, powerful and secure web applications across corporate Intranets, and e-commerce portals.

Installing MySQL under Windows

You can download the MySQL installer from http://www.mysql.com/downloads/index.html. Once you have it downloaded, double-click the file to begin the installation, and follow on-screen instructions (it's best to choose the typical installation for our purposes).

Testing the server

Assuming that everything installed correctly, you should now have a fully-functional server. Please note that you may have to restart your PC before the server will work correctly. To test your server, open up your favourite web browser and type http://localhost/ in the address bar, and you should see something similar to the image below in your browser.

This is the default Apache page. However, as we are going to develop in PHP, we will need to replace this with a file called index.php. First stop the Apache server (there should be an icon on your Windows task bar on the bottom-right to facilitate this). In the windows start menu, choose:

Programs->Apache HTTP Server->Configure Apache Server->Edit the Apache httpd.conf Configuration File

...and change the line that says "DirectoryIndex index.html index.var" to "DirectoryIndex index.php index.html index.var". Now the index.php file will be searched for first. Place any valid php file in the htdocs folder of your server (on Windows 2000 this defaults to C:\Program Files\Apache Group\Apache2\htdocs), name it index.php, and restart the Apache server. Now when you start your web browser and navigate to http://localhost/, you should see the results of your index.php file after it has been processed by the PHP interpreter.

Concluding notes

All of the software I have used in this tutorial are constantly being upgraded and improved, so the exact nature of the install procedure may also change with it. The installation will also be different dependant upon which operating system that you are using, for example Windows 98 will be different to Windows XP, and Linux will be different again.

If you have any difficulties in setting up your server, ensure that you have read all of the instructions with your downloads carefully, and also check the relevant web sites for additional help. I have deliberately strayed away from testing the MySQL installation as this is quite a complex issue, but rest assured that when you need to use it, you installation will support MySQL; it is a very easy insatllation. Now that you have a local server up and running, you are now ready to locally develop truly dynamic database-driven web applications. Enjoy!

About the author

Article by John Collins. John is a freelance web designer from Dublin. He is webmaster of http://www.design-ireland.net. Visit his site for more articles and tutorials on web development and technology related topics.