I’ve had lots of people ask my in the past, how to install PHP, MySQL and Apache for Windows XP. I recently formated my computer, and since I was going to do it, I thought I’d write out how to do this, for anyone who wants to know. My computer has SP2 installed.
Apache Web Server
Download Apache HTTP Server. I downloaded the current stable release, in this case: Apache 2.0.54. So download the Win32 Binary (MSI Installer), double click it, let it install.
Download PHP. I downloaded PHP 4.4.0.
I could have downloaded PHP 5.0, but as long as PHP < 5.0 gives me what I need, I won’t change. PHP 5 is the way to go. The tutorial below is pretty much the same, see the comments if you have problems. Unzip the contents, and put it all in the folder C:\php.
Copy the following files into your Apache2 installation directory. In my case it was C:\Program Files\Apache Group\Apache2.
php4ts.dll php4apache2.dll php.ini-recommended
Rename php.ini-recommened to php.ini. Open the php.ini in your favorite editor. Mine is EditPlus.
Search for ‘doc_root’ until you find the line:
Change this line to (in my case):
doc_root = C:\\Program Files\\Apache Group\\Apache2\\htdocs
Go to the directory: C:\Program Files\Apache Group\Apache2\conf\;
Add the following lines to the end of the file httpd.conf:
LoadModule php4_module php4apache2.dll AddType application/x-httpd-php .php
In the same file, add index.php to DirectoryIndex — this will make sure index.php will be picked up by the server automatically:
DirectoryIndex index.html index.html.var index.php
PEAR is an extension for PHP. These days PEAR is included with PHP, but you need to install it yourself. I use PEAR on all my PHP developments.
Ok.. Installing PEAR isn’t bad, here is what you do:
Open a command line window (i.e. Start->Run->cmd)
Go to the PHP directory, in my case C:\php. Type go-pear.bat. Follow the instructions.
The PEAR extension get installed in C:\php\PEAR directory.
Once PEAR is installed, go to the php.ini file in your Apache2 directory. Find the
;include_path = ".;c:\\php\\includes"
Remove the semi-colon (to un-comment it), and then add C:\php\PEAR to it
include_path = ".;c:\\php\\includes;C:\\php\\PEAR"
Testing it all – you really don’t need to, but before testing, restart your computer.
Test Apache Web Server
Once Apache is installed, you should be able to go to your favorite browser, type the following URL: http://localhost/ and have a test page load.
Go to the htdocs folder in Apache2 folder
Create a file called index.php, inside of that file put (be sure to remove the space between the < and the ?php):
<?php echo "php installed ok"; ?>
Go to your browser, type the following URL: http://localhost/index.php
If everything worked OK, “php installed ok” will appear on the screen.
Test MySQL and PHP using phpMyAdmin
This is the best web based MySQL Administration Tool (vital, trust me).
Unzip the contents into a folder phpMyAdmin in your htdocs folder.
Were going to use phpMyAdmin to control MySQL instead of the command line.
In the phpMyAdmin folder open the config.inc.php and type in the your root password for MySQL:
$cfg['Servers'][$i]['password'] = 'xxxxx';
Try and run phpMyAdmin in your browser: http://localhost/phpMyAdmin/
You’ll most likely get the error:
Client does not support authentication protocol requested by server; consider upgrading MySQL client
To fix this, do the following:
- Start the MySql Administrator, select “Startup Variables” from the menu, select the “Security” Tab. Check ‘Use old passwords’.
- Select “User Administration” from the menu, select the root user account and change the password for root user (other than null)
- Select “Service Control” from the menu, press “Stop Service” button and then press “Restart Service”.
Go back to config.inc.php and type in the your new root password for MySQL:
$cfg['Servers'][$i]['password'] = 'yyyyyy';
Try and run phpMyAdmin: http://localhost/phpMyAdmin/ — this should work now.
Using phpMyAdmin to create a database
In your htdocs folder create a file called testpear.php, in the file put the following (be sure to remove the space between the < and the ?php):
<?php require_once 'DB.php'; PEAR::setErrorHandling(PEAR_ERROR_DIE); $db_host = 'localhost'; $db_user = 'root'; $db_pass = 'password'; $db_name = 'dataBase_name'; $dsn = "mysql://$db_user:$db_pass@unix+$db_host/$db_name"; $db = DB::connect($dsn); $db->setFetchMode(DB_FETCHMODE_OBJECT); ?>
This will use the PEAR DB Extension to create a connection to your database. Before running this file make sure your database details are correct (i.e. name, user, password). Run this file in your browser, if no errors are listed, then your good to go.