Dynadot

Tutorial: How to Install Apache2 MySQL and PHP on Windows

Spaceship Spaceship
Watch
Impact
6
This tutorial is meant to show you how to install and set up the latest stable release of the Apache Web server, PHP, and MySQL to run on your local Windows machine for local testing and development. This can save you a lot of time and make learning and developing a lot easier.

These steps should work for setting up Apache 2 on most versions of Windows including Windows 98, Windows ME, Windows 2000, and Windows XP, but have only been tested on Windows XP. There may need to be some changes made for older versions of Windows so ask here if you need any help.

Installing the latest stable release of the Apache 2.0 series

STEP 1. Download Apache 2.x

Go to http://httpd.apache.org/download.cgi and scroll down to where you see Apache 2.x.x is the best available version. Just beneath that you'll see where it says Win32 Binary (MSI Installer): apache_2.x.x-win32-x86-no_ssl.msi [PGP] [MD5]. Download the apache_2.x.x-win32-x86-no_ssl.msi file and save it to your desktop or another location on your computer.

Step 1A. Install Apache 2.x
Browse to the location on your computer where you saved the apache_2.x.x-win32-x86-no_ssl.msi file that you just downloaded. Next, double click on it to open it up and continue through the installation by clicking Next until you come to the screen that says:

Server Information
Please enter your server's information.

Enter "localhost" without the quotes for both the Network Domain and the Server Name input boxes. Enter any email address you'd like in the Administrator's Email Address input box.

Now continue through the installation by clicking Next and leaving all the default values selected until you come to a screen that says:

Destination Folder
Click change to install to a different folder:

Click the Change button and change the folder name from "C:\Program Files\Apache Group\" to "C:\" without the quotes. Click OK and contiunue through the installation until you're finished.

Step 1B. Running Apache
Depending on which version of Apache and which versions of Windows you're running Apache may have been started for you already when you completed the installation. If it is, you'll probably see an icon in your system tray indicating that it's running. If it's not, you can start it by going to your Start menu --> Apache --> Start Apache in console or something similar. Depending on your version of Windows a Dos console window may open and remain open while you're running Apache.

Next create an index.html file, here's a sample one for you:
Code:
<html>
<body>
Apache is running...
</body>
</html>
Save the index.html file in your "C:\Apache2\htdocs" folder. Now browse to http://localhost/ or http://127.0.0.1 to see if Apache is up and running and if it's displaying the index.html file you just created. If you see "Apache is running..." or whatever you put in your index.html file then Apache is working. If you get a blank page or something else, you may try going back over the steps again or installing another version. If you're still unable to get it working or have any questions ask here for help. Your C:\Apache2\htdocs folder is where you'll need to save all your HTML and graphics files.

STEP 2 Download and Install PHP

Go to http://www.php.net/downloads.php and scroll down to where you see Windows Binaries. Download the zip package, not the installer. Save this file to your desktop or another location on your computer. Browse to the location on your computer where you saved the file and unzip it to your C:\ directory. Make sure you have this folder in your C:\ directory. Next rename the folder to "php" without the quotes. Now open up the php INI-DIST File located in your php folder.

Search for:
Code:
doc_root =

Replace with:
Code:
doc_root = "c:\apache2\htdocs"

Search for:
Code:
extension_dir = "./"

Replace with:
Code:
extension_dir = "c:\php\extensions"

Now save this file as "php.ini" without the quotes in your C:\Windows folder.

Next locate the php4ts.dll file located in your C:\php folder and copy or move it to your C:\Windows directory. You can do this by simply copying and pasting the file into your C:\Windows directory.


Step 2A. Configure Apache to work with PHP

Open up your httpd.conf file which should be located at C:\Apache2\conf\httpd.conf.

Now search For:
Code:
#LoadModule ssl_module modules/mod_ssl.so

Just below it add:
Code:
LoadModule php4_module "c:/php/sapi/php4apache2.dll"
Code:
[b]AddType application/x-httpd-php .php[/b]

Save the file and restart Apache. To test it you can create a php file, for example info.php with the following content:
PHP:
<?php phpinfo(); ?>
Save this file with a .php extension somewhere in your htdocs directory and browse to http://localhost/phpinfo.php to see if it's working.

Step 3. Download and install MySQL

Go to the mysql downloads page at http://www.mysql.com/downloads/index.html and scroll down to where you see MySQL database server and standard clients: Click on the Production release (recommended) version to go to the downloads. Scroll down to where you see Windows Downloads.

Click on the "Pick a mirror" link next to Windows 95/98/NT/2000/XP/2003 (x86). Scroll down and click on one of the links that is close to you to start downloading MySQL. Save this file to your desktop or another location on your computer.

Unzip the file to a temporary directory. You may have an option to Install Now if you're using a program like Winzip to unzip the files. If not just browse to the directory where you unzipped the files and click on the Setup program to start the installation. Select all the default options until the installation is complete.

After the installation is complete a window may open with a message that says "Create the mysql.ini file with default values and the user below." Go ahead and enter a username and password and click OK.

If the window doesn't open browse to your C:\mysql\bin folder and click on the MySQL icon(winmysqladmin.exe) to start the program. You can use this program to make changes to your mysql settings and start and stop the server.

Now you can test and make sure mysql is working as well as make sure you're able to connect with PHP by creating a php file, for example dbconnect.php with the following content:
PHP:
<?php
/* Testing database connection */
$link = mysql_connect("localhost", "root", "")
or die("Could not connect : " . mysql_error());
echo "Connected successfully";
?>
Save this file in your htdocs folder and browse to http://localhost/dbconnect.php to see whether it's working or not. If it is you should get a message that says Connected successfully. If you get any errors you may need to start MySQL which you can do by opening the winmysqlamin.exe file located in your C:\mysql\bin folder. You can use root as your username and just leave the password blank "" as in the example above in your scripts. If you need to create a database you can do so by going to your start menu --> run and entering cmd or dosprmpt in the input box. This should open up a DOS window. Next type the following commands pressing enter after each one:
Code:
cd c:\mysql\bin
mysql
create database MyDatabase;
The results would look something like this:
Code:
C:\>cd c:\mysql\bin
C:\mysql\bin>mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 4.0.17-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create database MyDatabase;
Query OK, 1 row affected (0.00 sec)
mysql>
That would create a database named MyDatabase, replace it with what you want to call your database. You can exit mysql and the DOS window by typing exit. If you want to learn how to create separate MySQL users and more you check out the MySQL manual http://dev.mysql.com/doc/mysql/en/index.html
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
sweet now i can test my sripts on my own pc :D
 
0
•••
GREAT !! Thanks for sharing ..
 
0
•••
This is my first post here, so.. Hello, everyone!

Anyway, I managed to install apache2 and php5 without any problems, but when I came to MySql, the installation was so different from the tutorial that I didn't know what to do. I guess the tutorial was for an older version of MySql... I've tried the mysql server instance config wizard a few times, but i can't seem to get it to work... What should I do?
 
0
•••
Version said:
Windows (x86) 4.1.13 37.7M

First: I tried to instal the mysql part today and in the instalation its says that its unable to run the service. so i go on to the next and hoping that its working but just what i thought it doesnt i get the error below what to do? :(

Error said:
Warning: mysql_connect(): Can't connect to MySQL server on 'localhost' (10061) in C:\Apache2\htdocs\dbconnect.php on line 12

Second: I made a folder called porfolio and placed my files in there and if i go to http://127.0.0.1/portfolio/ it does show the content of the directory and not the index.php file. what to do? :|
 
Last edited:
0
•••
maybe for newbies, it's nice to try apache2triad, found it's so handy to configure. They provide apache2, php5, mySql, phpMyAdmin, phyton, perl, xmail server, slimftpd, and more.. just check it by yourself

Regards
 
0
•••
i get error on line 3 of the testing MySQL part of the tutorial. i think the problem is that i dont know where/how to configure the .ini and that my folder is @ C:ProgramFiles/MySQL/. does anyone know how i can sort this out. thanks for all replys in advance
 
0
•••
Thanks deadserious, guys!
 
0
•••
Good tutorial!

Just in case people don't know, there are WAMP (an acronym standing for Windows, Apache, MySQL, and PHP) stacks that can be installed as a package:

XAMPP http://www.apachefriends.org/xampp-en.html XAMPP (GPL)
"XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. XAMPP is really very easy to install and to use - just download, extract and start."
Uniform Server rated this one their highest competition.
They are part of [http://www.apachefriends.org/en/ Apache Friends].

Uniform Server http://www.uniformserver.com/
"The Uniform Server is the pre-packed popular web development software. It is a small WAMP package, and it is also very easy to use and setup. At the moment Uniform Server includes Apache, PHP, Perl, MySQL, PhpMyAdmin, ..."
This is the one that I (matt) have been using for over a year. The most recent version has had a lot of improvements done to it.

SourceLabs http://www.sourcelabs.com/AMPstack.htm
This is a local Seattle company that also has a certified stack simular to SpikeSource. The have also created [http://swik.net/ Swik]-- "The free and open database of Open Source projects that anyone can edit."

SpikeSource http://www.spikesource.com/
 
0
•••
I personally prefer using Xampp.
it works really good and it installs without any prob.
I highly recommend using Xampp
 
0
•••
Then of course, the almighty WAMP Server themselves...

http://www.wampserver.com/en/index.php

I don't know if they're the original, but I've used this package for all my windows dev boxes. Great and easy install, easy "control panel" in the system tray... Easy config, right from the system tray.
 
0
•••
ya, all of these windows servers r best used for web development, when u want to test out all ur latest layouts and scripts.
also mods incase u dont want to make a fatal error on ur database.
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back