An updated version of this article
by Aman Singh is available here. [
http://www.coe.uncc.edu/~asingh/setup_apm.htm ] This update have
instructions for Windows XP Professional.
Apache, PHP4 and MySQL are open source technologies that allow you to create powerful and fast database-generated Web site applications. Apache is the most popular Web server. PHP has the unique distinction of being an open-source server-side scripting language that's both fun and easy to learn. Today, increasing number of Web developers are using PHP as a server side scripting language. Unlike Microsoft ASP scripting language it is available on both UNIX and windows platforms. MySQL is a fast, reliable, open-source database management system. This three open-source software has very respectable position among Linux/UNIX Web developers. Web developers using Windows O/S machines are not using this open source tools, simply because they feel that these tools are too difficult to install and set up.
This article makes it easy. It is based on my experience of setting up a working development environment for database backed Web sites on my Windows 98 machine. I started playing with PHP & Apache in the summer of 1999 and documented my efforts for personal reference. Later I rearranged my notes to complete this article. Recently, I again revised it to make it more useful with the latest releases of PHP, Apache & MySQL.
Although Apache and PHP were originally developed for UNIX machines, they are now ported to windows platform and have official releases for Windows OS. MySQL is a trusted & reliable RDBMS server working silently behind many database driven Web sites for many years on Linux servers. After it becomes open source, many efforts have been made to port it to Windows platform. Initially it was the most difficult task to find correct port of MySQL for Windows 98. But now MySQL is officially available for Windows platform and it is more easy to install. In this article I have summarized all steps, download sources, configuration tips to have Apache, PHP and MySQL running on a Windows 98 machine.
Having all three great open-source tools on your Windows PC is a very good starting point for developing database driven Web services and application. Once we get these technologies running, we can develop robust PHP/MySQL Web applications on our window development machine. We can test run these applications on windows and after that upload to more powerful Linux or UNIX servers.
After completing step-by-step instructions presented here, you will have a PHP/MySQL development environment in which you can start earning and testing these great technologies for robust, database-generated Web application development.
I assume that you have some HTML skills and that you know how to download and install software, create directories, unpack zip files and edit text files in a Windows environment. Also developing Web applications using PHP language required some knowledge of programming concepts. The downloaded tools - PHP & Apache server are compressed in .Zip format. If you do not have Winzip, then go to http://www.winzip.com/, download and install it.
The Apache server is the world's most popular Web server by a large percentage and is generally considered to be more stable than other servers. It is usually installed on UNIX and Linux systems, but is also available for Microsoft Windows platform. We will download the Windows version. To download the Apache server for Windows, directly go to win32 download page of http://www.apache.org/ at http://www.apache.org/dist/httpd/binaries/win32/ . At this page various packaged downloads are available. Latest release of Apache is available in two options, one is a big file of 5.1MB which contain Windows installer also. For the Windows users who have latest Microsoft Windows Installer version already installed their is a smaller file of 3.2MB. Read the instruction presented on this page and download the file suitable for your Windows setup onto your hard drive in a new directory c:\download\apache\. I selected the file apache_1.3.23-win32-x86-no_src.exe (size 5.1MB) for my installation.
Latest stable release of Apache is version 2. You must download this latest version. I have added installation and configuration comments for Apache 2, wherever necessary. File name for latest Apache 2 with Windows installer is apache_2.0.39-win32-x86-no_ssl.exe (size 6.2 MB). Apache 2 specific comments are identified as APACHE 2 [ Comment added on 1/7/2002 ]
PHP4 started as a small project to improve a home page and grew into one of the world's most powerful server-side scripts. The PHP community centered around www.php.net is very active. This is the place from where we will download the PHP4.
To download the PHP4, go directly to www.php.net/downloads.php and under "Windows 32 Binaries" click on PHP 4.1.2 zip package [5,824Kb] or whatever the latest version is. When you are asked to save the file, make a new directory called c:\download\php4 and save it there.
This windows 32 binary has compiled support for MySQL database. Some module files for other popular databases like dbase, MS-access are also included in this download. For other major RDBMS you have to download and install separate module files. For our development environment, we are going to use MySQL database, which support has been compiled in this binary distribution hence we doesnt need any other module to download.
The PHP 4.1.2 download is in a single compressed file of 5.8MB having .Zip extension. You will need the winzip package or similar tool to uncompress it.
MySQL is the database that your PHP4 will access to create dynamic Web sites.
To download the latest MySQL release go to http://www.mysql.com/downloads/mysql-3.23.html . At this page links are available to download MySQL in source as well as binary form for various platforms. Search for Windows downloads and under it click on MySQL 3.23.49 Windows 95/98/NT/2000/XP (12M) link to start downloading.
Save this file to c:\download\mysql on your hard disk. Also note that this download is also compressed in .Zip format and you will require winzip to uncompress it.
Installing the Apache server takes less than a minute. You will see that it uses the nice install interface that we know and love with Windows applications. Installing Apache is probably the easiest of the three components that you will be installing today.
In your Windows Explorer, go to c:\download\apache and double click on the .exe file that was downloaded, e.g. apache_1.3.23-win32-x86-no_src.exe. Keep clicking on the NEXT and YES buttons. After you click on the FINISH button, Apache will be installed.
APACHE 2 For Apache 2, the installation procedure is same as above.
Apache gives you a couple of options during the installation but they are not interesting to us right now, so just accept all the defaults for the installation.
If you are an ASP developer and have Personal Web Server installed on your machine, don't worry, you will be able to run both the Apache and PWS without any conflicts. You will simply have to shut one down while you run the other.
Configure Apache
The Apache server will not work until you configure it. Configuring Apache is very easy: you simply have to change one line in a text file called httpd.conf. You will find this file under c:/Program Files/Apache Group/Apache/Conf. You can edit it with any text editor, e.g. NotePad. You can also access this file by Start > Programs > Apache HTTP Server > Configure Apache Server > Edit the httpd.conf configuration file.
Open the file httpd.conf in a text editor. Then search for the line
#ServerName new.host.name
and replace it with
ServerName localhost
Then save the text file. There is a nice tool available with Apache to check the httpd.conf file proper syntax. Use this tool to check your httpd.conf file. Access the tool from Start > Programs > Apache HTTP Server > Configure Apache Server > Test Configuration.
APACHE 2
To configure properly for Apache 2 add a colon and port number with the ServerName.
Example:
ServerName localhost:80
To be able to serve pages, a server has to be running, just like any other application before it is used. You will now start the Apache server. Then you will open your browser and see if it displays HTML pages.
To start the Apache server, click
on Start > Programs > Apache HTTP Server > Start Apache in
Console. You should then see a DOS window that states that Apache is
running. This DOS window will always be open for Apache web server. Simply click
the minimize icon at the top right corner of this window to minimize it to
Windows taskbar.
Now, open up your browser and type
in http://localhost. If you should see a screen which reads
something like "The Apache server is now installed on this Web site", then you
have successfully installed the Apache server!
If it didn't work? There are a couple of things you can check:
Installing PHP4 consists of simply unzipping it. For uncompressing you will need WinZip or a similar program. There is no install interface as with Apache.
Go to c:\download\php4\ or the directory where you have downloaded the PHP file and double click on the .zip file. Extract the files into a new sub-directory called c:\php4win.
After unzipping, to check if you were successful, look in c:\php4win\. There you will find many files & subdirectories containing various files, then you have installed PHP4 successfully!
Configuring PHP4 consists of changing a few lines in a text file, renaming it and copying it and another file into the Windows directory.
To configure PHP4, create a sub-directory called c:\phpWeb. This is where your PHP files will reside. Rename the file c:\php4win\php.ini-dist to php.ini. Open this php.ini file with a text editor and change the doc_root and extension_dir lines so that they read as follows: only lines printed in bold text has to be changed.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
include_path = ; UNIX: "/
doc_root = "c:\phpWeb" ; the root Web
user_dir =
;upload_tmp_dir =
upload_max_filesize = 2097152
extension_dir = "c:\php4win"
enable_dll = On
Then move the two-file php.ini and php4ts.dll to c:\windows. If you haven't already, make sure you delete the php.ini file from c:\php4win as otherwise it may cause conflicts later.
After you have copied these two files, PHP4 is configured.
Although PHP4 is itself configured, we still will not be able to access it through the Apache server, as Apache has only so far been configured to read static HTML pages. We still need to tell Apache Server what to do when it encounters embedded PHP script in Web pages. To do this, we need to alter Apache's httpd.conf file again, the same file we changed earlier.
Find and open file
C:\Program\Apache Group\Apache\conf\httpd.conf in a text editor again. Then
search for the DocumentRoot and
# symbolic links and aliases
#
#DocumentRoot "C:/Programme
DocumentRoot "C:/phpWeb"
#this should be changed to
#
## This may also be .
APACHE 2 configuration needs one more directive to be changed. Find out the <Directory > directive few lines below the DocumentRoot. You will find specific instructions above this <Directory> directive as "This should be changed to whatever you set DocumentRoot to." Follow this instruction in its spirit and change it as follows:
#
# This should be changed to whatever you set DocumentRoot to.
#
#<Directory "C:/Program Files/Apache Group/Apache2/htdocs">
<Directory "C:/phpweb">
Then under the line AddType application/x-tar .tgz add the lines:
# For example, the PHP3 module (not part of the
# will typically use:
#
#AddType application/x-httpd-php3 .phtml
#AddType application/x-httpd-php3-source .phps
AddType application/x-tar .tgz
ScriptAlias /php4/ "C:/php4win/"
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .php4
Action application/x-httpd-php "/php4/php.exe"
Check closely for any typing errors, then save your changes.
Notice that in the http.conf file when referring to paths, Apache uses forward slashes ("/") instead of the more standard Window's backslashes ("\").
Notice also that a pound sign ("#") in front of a line comments it out so that it is not interpreted.
Notice also that the text /php4/ in the above code does not refer to a directory c:\php4 (which should not exist) but is a variable which we define to refer to the PHP directory c:\php4win.
In case you need to know later at some point, there are two ways to configure Apache for PHP4, as a CGI module or an Apache module. Here, we have installed the CGI module. You can also configure PHP4 as a Apache module, look for instructions in the install.txt file in the /php4win directory.
The changes you made in the http.conf file will not take place until you stop and restart your Apache server.
To stop the Apache server, restore
the Apache server DOS window and click on close icon in the top right corner of
it. To restart it again with use Start > Programs > Apache HTTP Server
> Start Apache in Console .
Then create a one-line test PHP file called "c:\phpWeb\test.php" with the following contents:
Today is <? print strftime("%m/%d/%Y"); ?>
Then open your browser and go to: http://localhost/test.php
If you see the words "Today is" followed by the actual date, then you have successfully installed PHP4! You must remember here that PHP is a very powerful scripting language with its own syntax, commands and rules for developing applications. PHP is widely used for developing database backed Web services by a large number of Web developers. To learn more about PHP language, its syntax and usage, visit the http://www.php.net/.
The MySQL package you downloaded is a ZIP file that contains setup files. You will first unzip the ZIP file into its own directory then execute the setup file, which has a nice interface similar to Apache.
In c:\download\mysql, double-click on mysql-3.23.49-win.zip and uncompress it in a separate directory. After uncompressing run the setup.exe. Keep clicking Next and Yes during the installation process until the MySQL is installed.
In order for PHP to be able to speak to MySQL, it must be started. This means that each time you turn on your machine and want to work with PHP/MySQL, you will have to start MySQL.
To start MySQL, go to c:\mysql\bin\" and double click on mysqld.exe. If a MS-DOS window opens for a second and then closes, you did it correctly! MySQL has been started.
For the Windows XP, You have to use a different command to start MYSQL. Click on mysqld-nt.exe to start MYSQL on Windows XP. This will start standalone MySQL server.
Thanks Philip Percival for this suggestion for Windows XP.
Now comes the big test: can Apache serve PHP files that talk to MySQL databases. To perform this test, you will create a PHP file that creates a MySQL database, then adds a record to it.
Create the file c:\phpWeb\testmysql.php with the following content:
<h3> Press RELOAD to add a record to the MySQL database:</h3>
<?
//establish user connection
mysql_connect("localhost");
//open up database
mysql_create_db("testdatabase");
mysql_select_db("testdatabase");
//create table
mysql_query("CREATE TABLE newone(firstName VARCHAR(25),lastName VARCHAR(25))");
mysql_query ("INSERT INTO newone (firstName, lastName) VALUES ('Amir', 'Khan')");
//display the information
$result = mysql_query ("SELECT * FROM newone");
while($row = mysql_fetch_array($result))
{
print ("Added record: " . $row["firstName"]." ".$row["lastName"]." <br>\n");
}
//close user connection
mysql_close();
?>
Each time you click on the RELOAD button, you will see that another record has been added to the database.
If you saw a name being added to the screen each time you clicked RELOAD, then you have successfully installed Apache, PHP4 and MySQL! Congratulations!
More information
Now that you have the Apache, PHP4 and MySQL installed on your machine, it is just the beginning of learning how to create robust applications with them.
I received many e-mail in connection with the problems faced by readers in installing & configuring the tools discussed here. I read every e-mail but it is not always possible to reply to each. I suggest you to first search the mailing lists archives at http://www.php.net/, http://www.apache.org/ and http://www.mysql.com/ for the solutions for problems with the respective tool. Also submitting your queries to these mailing list will always get attention and replies from a wider group of experienced open-source developers.
A comment section is included at the end of this page. I would like to read your comments and suggestions about this article.
Learning to develop software in a programming language always required some efforts. Although PHP is very easy language to program but developing Web applications are entirely different thing. To master the art of developing effective & purposeful Web applications, you will need to know more about Apache - the most popular, reliable & tested Web server. I like to suggest a very good book edited by Ben Laurie, Peter Laurie and Robert Denn, "Apache: the Definitive Guide" to everyone interested. Another good book, "Programming PHP" co-authored by the creator of PHP, Rasmus Lerdorf, explains the language syntax and programming techniques of PHP 4, in a clear and concise manner. Developing Web applications also required knowledge of relational databases and how to interact it using server-side programming. A nice introductory book, co-authored by Luke Welling and Laura Thomson, "PHP and MySQL Web Development", introduces readers to PHP and MySQL for the purpose of creating dynamic Internet sites.
|
You can order the books listed in previous paragraph and many more from Amazon.Com |
I recommend the following online resources for you to start learning more on Apache, PHP4 and MySQL.
If you need more information / tutorials / examples for Apache + PHP + MySQL go to your favorite search engine. All three are very popular open-source technologies and there are thousands of sources for information on them.
| samdarshipali@yahoo.com |
This article copyright Samdarshi Pali 2000-2002. All
rights reserved. | |
Standard Disclaimers about my Web site.
Readers' Comments (if you don't see anything below, try clicking here)