Wednesday, December 03, 2008

Apache + MySql + PHP on Windows (WAMP)

This guide helps you to install and configure Apache 2.2, MySql 5.0.26 and PHP 5 on a Windows machine.

Step 1 : Install Apache 2.2 (The Windows installer is named apache_2.2.6-win32-x86-no_ssl.msi)

- Accept all the default settings; fill in the required fields like site name, webmaster email ID etc., By default Apache runs on Port 80. Let is install itself as a Service so that it starts automatically when Windows boots-up.

- My installation directory is C:\Program Files\Apache Software Foundation\Apache2.2

Step 2 : Install MySql (The ZIP file is named mysql-5.0.27-win32.zip which contains setup.exe which is used to install MySql)

- I install it on C:\Program Files\MySQL

- Go through a Detailed Configuration; let it install on the default port 3306; install it as a service; add the MySql directory to the windows path.

Note : I normally disable Strict Mode during the configuration settings.

Step 3 : Install PHP 5 (The file is named php-5.2.6-Win32.zip which you would have to unzip)

- I install my PHP on C:\PHP5 directory

Now to the configuration part : -

Step 1 : Rename the file php.ini-recommended to php.ini (found inside your PHP directory; C:\PHP5 in my case)

Step 2 : Modify doc_root, extension_dir and upload_max_filesize (optional) inside your php.ini file (found in c:\php5) as shown below

doc_root = "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs"
extension_dir = "./ext"
upload_max_filesize = 8M


Step 3 : Enable MySql extensions by uncommenting (removing the ; before the line) in

extension=php_msql.dll
extension=php_mssql.dll
extension=php_mysql.dll


Step 4 : Configuring Apache to work with PHP - edit httpd.conf found in your conf directory inside Apache installation directory

Edit httpd.conf and add the lines below (remember to reflect your settings) after the LoadModule sections and before the 'Main' server configuration

PHPIniDir "C:\PHP5"
LoadModule php5_module "C:\PHP5\php5apache2_2.dll"

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Action application/x-httpd-php "C:\PHP5\php-cgi.exe"


Step 5 : Copy libmysql.dll (found in your MySql directory) into your Apache's Bin directory.

Finally : Check to see if your MySql's bin directory and PHP's home directory are available in your PATH (Environment variables)

All set! Now, lets check if your installation is done.

Create a file called as phptest.php type
<?php phpinfo(); ?>
and save it inside your Apache's htdocs folder.

- Start/restart Apache service and access http://localhost/phptest.php through your browser.

This should throw up a long page with the list of extensions enabled. Search to see if MySql is enabled. If you find an entry for MySql in the extensions then you have successfully installed AMP on W.

No comments: