April 23, 2008

Install Tutorial for Apache PHP PEAR MySQL phpMyAdmin on Windows XP

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.
PHP Run-time
Download PHP. I downloaded PHP 4.4.0. 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.
Code:

php4ts.

dllphp4apache2.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:
Code:

doc_root =

Change this line to (in my case):
Code:

doc_root = C:Program FilesApache GroupApache2htdocs

Go to the directory: C:\Program Files\Apache Group\Apache2\conf\;Add the following lines to the end of the file httpd.conf:
Code:

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:

Code:

DirectoryIndex index.html index.html.var index.php

PEAR Extension
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
Code:

;include_path = ".;c:phpincludes"

Remove the semi-colon (to un-comment it), and then add C:\php\PEAR to it
Code:

include_path = ".;c:phpincludes;C:phpPEAR"

MySQL DataBase
Download MySQL (runtime) and MySQL Administrator (Admin program). I used MySQL 4.1 Generally Available (GA) release. Download, unzip, and install both.
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.
Test PHP
Go to the htdocs folder in Apache2 folderCreate a file called index.php, inside of that file put (be sure to remove the space between the <>
Code:

echo "php installed ok";
?>

Go to your browser, type the following URL: http://localhost/index.phpIf everything worked OK, “php installed ok” will appear on the screen.

Test MySQL and PHP using phpMyAdmin
Download 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:
Code:

$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:

  1. Start the MySql Administrator, select “Startup Variables” from the menu, select the “Security” Tab. Check ‘Use old passwords’.
  2. Select “User Administration” from the menu, select the root user account and change the password for root user (other than null)
  3. 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:
Code:

$cfg['Servers'][$i]['password'] = 'yyyyyy';

Try and run phpMyAdmin: http://localhost/phpMyAdmin/ — this should work now.

Test PEAR
Using phpMyAdmin to create a databaseIn your htdocs folder create a file called testpear.php, in the file put the following (be sure to remove the space between the <>
Code:

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.

related post Install xampp

No comments: