guide to setting up PHP-MySql-Apache on Windows

This guide is meant to help those who want to start creating web applications or dynamic web pages with php and mysql on an apache web server but don’t know how to start. Hope it helps :)

The guide will follow these steps:

1. Installing and setting up Mysql

2. Installing and setting up Apache

3. Installing Php

4. Configuring Php

5. Testing the installation

6. Installing and setting up phpMyAdmin

MySql

Download the MySql essentials installer from the mysql website here.

Start the installation and proceed along typical installation (unless you know what you are doing). During the installation you will be prompted to sign up for a mysql account. Doing so will let you post at their forums and some other benefits.

As the installation finishes, the MySql configuration wizard will appear.

There are two types of configurations, standard and detailed. Standard configuration is good enough for starters, but if you are sure of your use of the database, you might go for detailed. One thing you can do in detailed is that you can specify the port to use for the database, so that you might free it up incase you are using a firewall.

During this step, the security configuration is very important. Do not allow root access from remote machines or create an anonymous account as that creates security vulnerabilities.

The wizard will now finalize the configuration settings, write the necessary scripts and start the database engine. In case you are using a firewall and the database tries to use a blocked tcp port, you will be prompted to unblock it in this step. Do that.

Apache

Download the apache web server installer from here

Though Apache2 has some improvements over Apache for win32, but it has issues with php. So it is suggested that you download Apache 1.x (latest is 1.3.37). it is a simple executable file. Download it and run the installer.

After a few clicks, the installer will ask for the server information. If you are installing it in a remote machine, give localhost in the first two blanks, and any email.

Choose to run it as a service for all users.

In the next step, choose custom if you don’t want to install the documentation. Else proceed to complete the installation.

Php

Download the latest version of php from the php website here

Though there is a windows installer available, it is better to download the windows zip package and configure php manually.

Unzip the files to anywhere you want and rename the directory to something short (mine is C:\php)

Take care that the path to the php directory does not have any spaces. That is known to crash the server.

Configuring php

Add the php folder to windows path by Start->Control Panel->System->Advanced->Environment variables. There scroll down the system variables list, double click on PATH and append the directory at the end.

For Apache

Copy the php5ts.dll file in the php folder to the bin directory under Apache’s installation directory.

Copy the file php.ini-dist to the Window's directory and rename it php.ini

(The php.ini file controls how PHP behaves. The Zip package comes with a couple of examples of this file, php.ini-dist being one of them.)

From the Start menu, select Programs > Apache HTTP Server > Configure Apache Server > Edit the Apache httpd.conf Configuration File.

1. At the end of the LoadModule section, add

Code:
LoadModule php5_module "C:/php/php5apache.dll"

Use the path to your php directory instead of C;/php in here.

2. At the end of the AddModule section add

Code:
AddModule mod_php5.c

3. Find where it says <IfModule mod_mime.c> and add

Code:
AddType application/x-httpd-php .php

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

4. Find the line that begins with DirectoryIndex and change it to read

Code:
DirectoryIndex index.html index.php

This lets index.php be a main file in a directory

Close and restart Apache by running the commands

Code:
NET STOP APACHE 

NET START APACHE
One after the other.

For MySql

Open the php.ini file that was earlier placed in the WINDOWS directory and open it in notepad.

Scroll down the file and find the line beginning with extension_dir. remove whatever is there between the quotes and add the following line in there

Code:
C:\php\ext
Provided your php installation is in C:\php. Else use what is applicable.

Next scroll further down till you reach the section for Dynamic Extensions there you will find that a number of extension dlls are listed, and a ‘;’ is present at the start of each line. Find the lines saying

Code:
 ;extension=php_mysql.dll

;extension=php_mysqli.dll
and remove the semicolon.

While you are here, you can also enable the extension for php_mbstring, as it would be needed later for setting up phpMyAdmin.

Testing the installation

Apache

Open notepad and put in the following code

Code:
 <?php

phpinfo();

?>
Save the file as phpinfo.php under htdocs directory under the Apache installation directory.

Open up your web browser and give the following address in the address bar

Code:
 [url]http://localhost/phpinfo.php[/url]

If Apache and php has been properly connected, went well, a page listing all the information about your php installation would be displayed.

MySql

Create another php file with the following code

Code:
<?php

echo mysql_connect ('localhost', 'username', 'password');

?>
place ‘root’ as username and you MySql server password as password and save the file as mysqltest.php under htdocs.

Run the script in your browser. If connection is working, the browser window will display something like

Code:
Resource id #2

Congratulations!!! You have successfully setup the Apache web sever and MySql database server in your machine for php:hap2:

Installing and Configuring phpMyAdmin

phpMyAdmin is a popular, powerful web-based interface for administering MySQL databases, written in PHP and published under the GNU General Public License. It works as a nice replacement of the command line and is very convenient to use when you are developing applications with php and MySql using the Apache web server.

Install steps

Download the zipped folder of phpMyAdmin from here and unzip it to /Apache/htdocs. Rename it something short (phpmyadmin in my pc)

Open a browser and enter http://localhost/phpmyadmin/index.php in its address bar.

The phpMyAdmin welcome page should be displayed, but with some error, like the following

Create a file config.inc.php under the directory C:\Program Files\ApacheGroup\Apache2\htdocs\phpmyadmin\ and put in the following code

Code:
<?php

$cfg['PmaAbsoluteUri'] ='http://localhost/phpmyadmin/';

$cfg[blowfish_secret] = 'funkymonkey';

$i = 1;

$cfg['Servers'][$i]['host'] = 'localhost';

$cfg['Servers'][$i]['connect_type'] = 'tcp';

$cfg['Servers'][$i]['auth_type'] = 'cookie';

$cfg['Servers'][$i]['extension'] = 'mysqli';

?>
For blowfish parser, you can use any string within 46 characters..:)

Save and close the file

In the php.ini file, if you haven’t already uncommented the extension php_mbstring.dll, do it now.

Close and restart Apache.

Reload the phpmyadmin script in your browser. The login page should be displayed now.

Enjoy.........:clap: :clap: :clap:

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

Resources:

php manual

mysql docs

apache docs
 
it's not crapping man..suggestions always welcome..:)

i've begun php only recently, and wasnt aware of this. so i had to figure out the hard, or 'google' way. thought all the info in one place might help others..hence the guide

also, i feel that building something urself is more useful than getting something prebuilt, but that's only my POV :)
 
ah yes. I've been thru those painful days when i didnt like apache much and setting up and changing php versions on IIS was always a pain. found xammp easiest of all packs. works flawless. comes power packed with

-webserver (apache)
-db server(mysql)
-mailserver(mercury)
-ftp server(filezilla)
-phpmyadmin
-openssl
However if you plan to put it on production, you should go thru docs to make it secure.

Above all features, it has a tomcat addon which i've found easiest to setup in comparison to any other Java server. Now whenever i need to run anything php/mysql based i just download xammp and kickstart.

My point is saving effort in installing and putting that in working on what you'd really want to.
 
Gr8 guide dude .. really gonna help me soon But I am intto other coding well will try it today :) Repped you >. Again rocking information ;)
 
BTW, i just used LAMP for setting up a forum based on "Simple Machine Forum" on our local intranet in my office.

It's working gr8!!!
 
thanx for ur reps guys..:hap2:

@montylee: of course it would..linux is always great for hosting web servers..:)

@Arya: thanx for the info mate..it sure looks good. if its secure and stable, and one feels comfortable with it, it is a better bet than sweating away with details..:)
 
gr8..i made thread for configuring something manually, and here a list is being made of the ways to do it automatically..:)

single thread..dual purpose :p
 
i too had a tough time setting this up under iis 6 (win2k3 srvr) to host phpbb for my dept's BB....but finally cud do it after abt a week of struggle...i'd hv been better off using Apache rather....anyways i guess there are no automated/prebuilt tools for configuring php n mysql under IIS. often, the version mismatch between the php ini file and php_mysql(i) extension(s) and libmysql library is the culprit....and in some cases( at least in my case) you do require to insert the php.ini path into the registry to make it work....hope this little piece of info wud help others who are trying to setup under iis 6...
 
Back
Top