SETUP APACHE2.0.53,PHP5 & MYSQL4 ON WINDOWS XP
rcfearn@utas.edu.au



DISCLAIMER - I AM NOT A AN APACHE, PHP & MySQL GURU - I KNOW VERY LITTLE ABOUT THE INNER WORKINGS OF MOST OF THE CONFIGURATION FILES ASSOCIATED WITH THESE PROGRAMS. I HAVE HOWEVER LEARNT THROUGH NECESSITY HOW TO GET APACHE, PHP & MySQL RUNNING TOGETHER IN RELATIVE HARMONY.

THE FOLLOWING WALKTHROUGH WAS PERFORMED ON A STANDARD INSTALLATION OF WINDOWS XP PROFESSIONAL WITH SERVICE PACK 2 INSTALLED.

Please do not email me with alternative versions of this tutorial unless they are to correct mistakes made throughout this document. I have written this down whilst performing the installations and changes to config files. There were no previous versions of any of the three programs installed on the machine I used.


The versions may change overtime - I will not keep this up-to-date.
The filenames and information provided on this page were valid on 18/3/05

Download Apache V2.0.53

Filename:
apache_2.0.53-win32-x86-no_ssl.msi

Location:
http://httpd.apache.org/download.cgi

Download PHP V5.0.3

Filename:
php-5.0.3-Win32.zip

Location:
http://au.php.net/get/php-5.0.3-Win32.zip/from/this/mirror


Download MySQL V4.1.10

Filename:
mysql-essential-4.1.10-win32.msi

Location:
http://dev.mysql.com/get/Downloads/MySQL-4.1/mysql-essential-4.1.10-win32.msi/from/pick#mirrors

1 - Agree to the apache terms & conditions and hit next until you get to the "Server Information" screen (figure 1). I usually title the servers etc as "localhost" and the email as "me@localhost".

FIGURE 1


2 - Choose "Typical Installation" on the following screen. You can choose custom if you like but this walkthrough may not work if you do.

3 - Choose the directory for Apache - I am going to assume that you stick with the default directory which is C:\Program Files\Apache Group

4 - Select install and let it do its thing.

5 - A couple of console windows will open and close (you may get a firewall warning here - I allow the connections when I get the warning)

6 - Click "Finish" and your done.

7 - Check that apache is working correctly by opening you browser and typing "localhost" (without the quotes) you should get the Apache homepage with a message that says

Seeing this instead of the website you expected?

If you have this page then you have successfully installed the Apache Webserver on your machine :-)

You should notice a small icon down the bottom right of the screen. It is a little feather and a blue arrow pointing right. If you hold your mouse over this it should say "Running all apache services". You can double click this and you will get the Apache Service Monitor which allows you to start and stop apache. You will need to restart Apache once PHP is installed and also if any changes to the Apache config files.

INSTALLING MYSQL
1 - Run the MySQL msi file you downloaded

2 - Once again I am assuming that you select the "Typical" Installation on the second page of the installation wizard. You will need to select the custom install if you do not wish to install to the default MySQL directory however for the purposes of this walkthrough I will assume that you are installing the the default directory.

3 - Once it is installed you can sign up for a MySQL.com account (I am skipping this)

4 - You will then get another window that asks you whether you want to configure MySQL now. Check the box "configure now" box and click "Finish"

5 - You will now see the "MySQL Server Instance Configuration Wizard" window select next

6 - Select "Standard Configuration" then click next.

7 - Check the "Include Bin Directory in Windows PATH". I select this because I like to work from the command line when I am using MySQL. Mainly because remote servers like Smartyhost etc only allow you to access their MySQL services via the command line. Leave the other boxes checked too and hit "Next"

8 - Enter a password (DONT FORGET THIS PASSWORD!! you need to use it when you connect to mysql from either the console or PHP) for the MySQL server. Select "Next"

9 - Now select "Execute" and you should see the four white dots change to blue as the MySQL server is initialised and fired up. You may get another firewall alert here, once again I allow the service to run.

10 - The initialisation screen hung when applying the security settings and I got a warning that it had not worked. I hit retry on the warning screen and now its ok. (Probably caused by the firewall halting it).

11 - Select "finish" now that it is no longer greyed out.

12 - Ok, In theory th MySQL services are now running. To check this do a CTRL+ALT+DEL and check in the processes to see whether you can see it (figure 2)

FIGURE 2

Provide you can see that this process is running you have successfuly installed MySQL.
Seems easy doesn't it!! It is the PHP module that tends to cause all the grief.

INSTALLING PHP
1 - Extract the PHP zip file to anywhere you like as long as you can find it!

2 - Rename the folder it has been extracted to to PHP

3 - When you open the PHP folder you should see a bunch of .dll files and four folders
- dev
- ext
- extras
- PEAR
Make sure that these files & folders are located immediately within the PHP folder.

4 - Now copy (or cut) the PHP directory and paste it to the system root e.g. C:\

5 - Ok - you now need to edit the Apache config file so that it loads PHP as a module when Apache starts. From the start menu in window go:

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

6 - The Apache config file should now be open in Notepad. Go to the bottom of the file and paste the following lines of code (including the # if you like these are comments in the config file):

#############################################################
#PHP 5

ScriptAlias /php/ "c:/php/"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php/php-cgi.exe"

#############################################################


7 - Now save you config file and close it.

8 - Double click on the Apache icon in the bottom right (little feather and arrow). When the "Apache Service Monitor" window pops up make sure Apache is selected in the top panel and then click "restart". This should fire up Apache with the PHP module.

9 - check that the PHP module is working by going to the htdocs directory in the Apache folder (this is the default directory when you browse to localhost):

C:\Program Files\Apache Group\Apache2\htdocs

10 - Create a new file called "test.php", open it in notepad and paste the following code into it:



<?php

for($i=0;$i<10;$1++)
{
echo "Testing PHP : $i
";
}

?>


11 - Now run the file in your browser with the following address:

localhost/test.php

you should get the following output in your browser:

Testing PHP : 0
Testing PHP : 1
Testing PHP : 2
Testing PHP : 3
Testing PHP : 4
Testing PHP : 5
Testing PHP : 6
Testing PHP : 7
Testing PHP : 8
Testing PHP : 9

If you do not get this output you should go back through this set of instructions and make sure you have done everything correctly.

CONFIGURING PHP TO RUN MySQL
1 - Ok if you have got this far you have successfully managed to get Apache to fire up the PHP module when it starts. However this is not the end of it as we still need to configure PHP to run MySQL. This was previously packaged as a default option with PHP but apparantly things have changed with new versions of PHP & MySQL so it is currently necessary to configure PHP manually.

2 - Now go to your PHP directory (C:\PHP), rename the "php.ini-recommended" to "php.ini"

3 - Double click the "php.ini" and it should open in notepad. Do a search for MySQL and you should come accross a line like this:

;extension=php_mysql.dll

4 - Remove the ";" from the start of this line thereby uncommenting this line (; are comments in PHP) now save the file and close it.

5 - Add the following new line to the test.php file we created earlier just before the ?> at the end of the file, save the changes and then refresh/reload the localhost/test.php file:

phpinfo();

6 - You should see quite a lot of information appear in the browser. If you scroll down (or about 7 "Page Downs") you should see a section devoted to MySQL settings (Figure 3)

FIGURE 3

7 - If you can see this information your MySQL module is being seen by PHP.

8 - To double check this you should add the following line to the test.php file before the ?> at the end. (You can delete the phpinfo(); line now we dont need this):

mysql_connect("localhost","root","[YOUR PASSWORD]");

Where [YOUR PASSWORD] is the password you used when you set up MySQL.

9 - When you refresh the page you should only see the original output we created. If you get a warning similar to:

Unrecognized function mysql_connect() in test.php then something has gone wrong and you will need to go back and make sure you have followed the steps correctly. (provided I have written them correctly!!)

HOW TO USE THE MYSQL FROM WINDOWS XP COMMAND LINE
Ok - Now you are all done and can get back to doing important stuff like assignments etc.....

Just some wrap up notes.

1 - If you want to create a database and some tables in MySQL go to the RUN option in your start menu and type CMD to get the windows "XP" command line up.

2 - Now type:

mysql -u root -p [press enter] and then type in the password you assigned to MySQL when you were installing it.

3 - You should now have mysql> as the prompt.

4 - To create a database type:

create database myFirstDB (or whatever you want to call it)

5 - You now need to select the database with

use myFirstDB;

6 - To create a table do something like this:

create table user(
userid int AUTO_INCREMENT PRIMARY KEY,
firstname varchar(25),
lastname varchar(25)
);

7 - Provided you dont get any warning you can view this table with either:

show tables; (shows all tables in the myDB database)
or describe user; (outlines the field that make up the 'user' table you just created)

8 - Add an entry with:

insert into user (firstname,lastname) values("Rob","Fearn");

9 - View the entries in the table with:

select * from user;

----------------------------------------------------------------------------------

If you have made it this far then my work here is done! Checkout the MySQL & PHP manuals for more information about connecting and querying databases. The connection info is in the PHP manual and the table creation, selection, deletion stuff is in the MySQL manual.

Please remember that this is only a guide to save you some time, I am aware that there are many alternative configurations for PHP, MySQL & Apache but I am happy with this one as it seems to work fine for me. Also note that at present I have not configured Apache to run PHP script in .html files they need to have the .php extension. This is probably pretty easy to work out I am pretty sure it is located in the Apache Config File somewhere. If someone can be bothered finding it send me an email and I will append it to this document.

meiking   2005-04-19 11:35:47 评论:0   阅读:692   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

谢智的个人博客 @CSS by self