Domain Empire

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.
help

while installing this message appears:
only one socket per port (...../network address/port)
no listening port available..unable to open..
make_sock: cannot bind to address 0.0.0.0.80

after installation, when i tried running apache -->start= no installed service name apache2

what next?
 
Last edited:
0
•••
Originally posted by redhippo
deadserious
are you running apache on your desk-top?

i have a copy of apache and am interested in running it. will it mess up other software in my computer?

while installing this message appears:
......
make_sock: cannot bind to address 0.0.0.0.80

after installation, when i tried running apache -->start= no installed service name apache2

what next?

Yes I run apache on my home machine and have been for quite some time. I've never had any problems with it messing up other software.

And the make_sock error you're getting I think is probably because IIS is already running on port 80. I would try stopping IIS and then running the apache installer again. You won't be able to run both servers on port 80 at the same time.
 
0
•••
what is the IIS? how do i disable it?
 
0
•••
0
•••
i am using windows XP home.
cant find "services" on control panel. would disabling it cause internet connect problems?
 
0
•••
No this shouldn't affect your internet connection.

I'm not sure it will be installed on xp home, but from your control panel you can try going to performance and maintenance --> Administrative Tools --> Services. Or if that don't work try right clicking on the 'My Computer' icon and selecting Manage. Then down at the bottom you should see Services and Applications, expand that and select services and the right pane should update with all the services listed.

You can also check in your add/remove programs -> add/remove components and see if Internet Information Services is even installed there.
 
0
•••
followed instructions but cant find any IIS?:(
 
0
•••
Are you running a firewall or some other software that may be running on or blocking port 80? Or maybe your isp blocks port 80?

I would try and disable any services that you have running including chat programs such as trillian, icq, etc. and then run the apache installer again using the repair option and see if that works.

If that don't work you can run the installer again and try installing it on port 8080 rather than 80. There should be an option for this when you run the installer. Then after it's installed rather than calling up http://localhost you would call up http://localhost:8080

Well I would try them things and see if they work and if not then I'm sure there are some other options to try and get it working. :D
 
0
•••
tried option two reinstalling/port8080= fail

how do i disable icq? etc
how do i know if my isp blocks my port 80
 
0
•••
Sucess! disable my "SKYPE" phone! almost reach end of step three: cannot find php\htdocs

apache console shows:

syntax error line 173
c:/apache2/conf/http:config

cannot load c:/php/sapi/phpapache2.dll
the specified module cannot be found
 
0
•••
Originally posted by redhippo
Sucess! disable my "SKYPE" phone! almost reach end of step three: cannot find php\htdocs

apache console shows:

syntax error line 173
c:/apache2/conf/http:config

cannot load c:/php/sapi/phpapache2.dll
the specified module cannot be found

Try changing that line in your httpd.conf file to:

c:/php/sapi/php4apache2.dll

And then start or restart apache. B-)
 
0
•••
Try changing that line in your httpd.conf file ? where
is this under apache or PHP?


there is no htdocs file or httpd.conf file under PHP folders
 
0
•••
Well it looks like you have added this line in the httpd.conf file or else I don't think it would be there. It will be the same file you initially added that line to. The httpd.conf file is apache's configuration file.

C:\Apache2\conf\httpd.conf is where it should be located if you installed to the directories listed in this tutorial. It looks like you just made a typo when adding that line :)
 
0
•••
i have redone the step 2A but i get this message:

"http://localhost/phpinfo.php=The page cannot be displayed"

maybe i save the test php file in the wrong place?
 
0
•••
Did you get the first part working with your index.html file and calling it up at http://localhost ?

The PHP file you saved should be in the same directory as your index.html file, C:\Apache2\htdocs. Open up that folder and double check to make sure it's there.

If that don't work I would try going through the configuration steps for your httpd.conf again and double checking things, then restarting apache and try again.
 
0
•••
thanks for the tutorial. completed it.!! what can i do next?
is it possible to use apache as my desktop server for my web site? how?


B-)
 
0
•••
This tutorial wasn't really meant for showing you how to run your web site from your own computer, but more for just using your computer for local testing and development. I wouldn't recommend actually running your site from you computer. This could lead to you getting kicked off your isp, your computer getting hacked and other not so good things.

If you really want to though, it's sure possible. You can use a service like http://www.zoneedit.com/ for your DNS.
 
0
•••
ya, like you can run MySQL and all its queries and PHP and stuff right? thats what i thought you could do with it, and that is what i wanted to be able to do.
 
0
•••
Originally posted by iDeviseFlash
ya, like you can run MySQL and all its queries and PHP and stuff right? thats what i thought you could do with it, and that is what i wanted to be able to do.

Yea It would be just like having root access to the MySQL / PHP / Apache, etc.. You then have the ability to do anything you want, run queries, modify settings, however you please and such. :)
 
0
•••
do you know how i can now install a control panel so i can access the server away from my home? Does it require any editing of apache or anything like that?
 
0
•••
.ie said:
do you know how i can now install a control panel so i can access the server away from my home? Does it require any editing of apache or anything like that?

You can make the server accessible by changing the ServerName in your httpd.conf file to your IP address. You might want a static IP address if you're going to do that. You could also use a dns service and go all out and set up a real hostname, but using your computers IP address would probably the easiest way.
 
0
•••
Great Job

Thank you for this tutorials ... I tried figure out what I need to create simple form... thought it will be simple... with dreamweaver.. .got a form .. learn i need to learn more and more and more...
Your tutorials are great tell for total newbie like me step by step what to do how to do....... I do not want to learn much programming ... just want to learn how to create simple form that interact with people...... and here I am... I found I need server on my machine etc etc.. but what and how ..YOU EXPLAINED PERFECTLY .. thank you. I only wish it was easier way.. to install those forms... like email etc.... and autoresponders... may be it is but have not found it yet :) Had to learn coldfusion anyhow .. so.. hope that it can run on apache..
Thanks again foir tutorials :))

I am doing that right now..want to check some tutorials for php... wish i did not have to learn those :( 50 old grandma had to learn programming .. fun eh ? :) Well it is still better than watching silly movies on tv... last 8 years all I have been doing is learning .. and it is never ending story :) graphics.. software.. and now that !

By the way excuse my poor English ... it is my second language. Anyhow you might find that tip useful.. for any needs. Since I am confined to wheelchair .. i started learning.. all softwares I need.... and it is hard with financial limited resources. Anyhow... I learn a lot from forums like yours... but also found that I can use paid sides...that offer video for sales. they usually offer some introduction movies to watch ... and if i need to just grasp concept... before I start learn details... i use them. It is quick way to get around .. and then join forums like yours... to search for more...

One site I use very often is www.vtc.com - hips of videos for graphic softwares etc... so can grasp basics for free.

Again thanks for tutoral about Apache and php:)
 
0
•••
thank you

OH MY GOD.... SORRY FOR SHOUTING HERE... BUT IT IS FROM HAPPINES!!!!
By reading your tutorials .. and mistakes people made ... My first local server works. T H A N K YOU SOOOOOOOOO MUCH! BRILLIANT TUTORIALS... step by step like for dummies but .. that is what i am now still dummy old lady :)))
 
0
•••
LoadModule php4_module "c:/php/sapi/php4apache2.dll"
I think needs to be changed to:
LoadModule php5_module "c:/php/php5apache2.dll"


I was having similar problems as RedHippo and noticed the date this thread was started.

I could be wrong but I think the file names in the latest version of php may have changed. I have now made the above changes in the appache/conf/httpd file. It seems to be working.

I never could get php to work. I wondered if the problem could be this "replace with" code: extension_dir = "c:\php\extensions". My version of php has a folder that looks like this "c:\php\ext", (there is no "c:\php\extensions") so I tried changing that, but still no success.

-traderone
 
Last edited:
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back