Published on 2003-08-31 by John Collins. Please follow me on Twitter for more:
When designing a web application, as opposed to a web site, you will need to make 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 possess 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, where you need to upload your work to their web server before you can test it. This can be a time-consuming process.
In this tutorial, I will show you how to easily set up your own web server on your local PC, using freely downloadable software. The combination we will be working with is:
In order to understand the relationship of these various technologies and how they fit together, examine the following diagram:
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 the user and the server for input and output.
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.
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:
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 unusual trend. As PHP derives its syntax from C/C++ and Perl, 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, JSP (which requires Apache Tomcat), Python 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 due to its power and ease-of-use.
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.
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.
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).
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 following screen in your browser:
This is the default Apache page. However, as we are going to develop in PHP, we will need to replace this page with a file called index.php. Firstly 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 FilesApache GroupApache2htdocs), 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.
All of the software I have used in this tutorial are constantly being updated and improved, so the exact nature of the install procedure may also change with it. The installation will also be different dependant upon the 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, your installation will support MySQL; it really is a very easy installation. Now that you have a local web server up and running, you are ready to develop truly dynamic database-driven web applications on your local PC. Enjoy!