How to Install Apache, PHP and MySQL on Windows Vista / Windows 7

This is a guide about Installing Apache, PHP, and MySQL on Windows Vista or Windows 7. Although setting up Apache, PHP and MySQL on Windows Vista / 7 is pretty much the same like setting up Apache, PHP and MySQL on Windows XP, it seems some people are having problem with it, although the only difference between those two is just there is User Account Control (UAC) in Windows Vista that basically prevent you from writing / editing files inside Program Files directory if you aren’t opening that files with Admin priviledge even if your account is in Administrator group. And this guide tells you how to configure Apache, PHP, and MySQL even when you installed it to Program Files directory without disabling UAC

Before we begin … this guide is compatible and has been tested with Windows 7 although the screenshots used here is showing the installation process under Windows Vista but that’s because back when i write this i’m still using Vista

Also it doesn’t matter whether you have x86 or x64 version of Vista / 7 installed. The only difference in this case is, if you’re running the x64 version, the Program Files directory for 32-bit program is called Program Files (x86)

And here goes the guide…

Prerequisite

Apache HTTP ServerDownload Apache – Please see Update right below this before downloading this

PHP for WindowsDownload PHP – Please see Update right below this before downloading this

Make sure to download the Thread Safe version because we’re going to load PHP as Apache module

MySQLDownload MySQL

If you prefer a smaller version you can choose to download the Essential version to save your time and bandwidth which is really useful if you have slow connection speed like me

At the time i wrote this the latest version of Apache is 2.2.15, PHP 5.3.2, and MySQL 5.1.45

Update

Because PHP no longer provide the PHP VC6 binary since version 5.3.6 directly on their website, there are two options for you to choose from:

1. Stick with PHP 5.3.5 VC6 and Apache binaries from official Apache website (the last version of PHP that is compiled using VC6) and can be downloaded from here

2. Use the VC9 version of PHP 5.3.6 and higher and also use Apache VC9 binaries built by www.apachelounge.com

If you’re going with option 1 then you can just simply follow the guide above, but if you choose option 2, the easiest way to install it is:

1. Download Apache binary from apachelounge.com and then download VC9 PHP from PHP website

2. Extract the apache into C:\ (so the apache directory ended up in C:\Apache2)

3. Open httpd.conf in C:\Apache2\conf and:

# Search for DocumentRoot "c:/Apache2/htdocs" and replace it with
DocumentRoot "c:/htdocs"

# Right above the DocumentRoot add ServerName
ServerName myhost.com

# Then search for Directory "c:/Apache2/htdocs" and replace it with
Directory "c:/htdocs"

4. Now run command prompt as administrator and then type:

cd /d C:\Apache2\bin
httpd -k install

5. As for the rest (PHP and MySQL setup) you can follow the guide below :)

Installing Apache on Windows Vista / Windows 7

1. First of all run the apache installer until you reached this Apache server information screen and fill in localhost (or other value you want but to make it simple i just put localhost)

Apache Server Information

2. Then choose Typical for the setup type

Apache Typical Setup

3. And then when asked to choose the installation directory, make sure to use the default path to install it to program files directory as shown below (because that’s what this guide all about, to assist you to install apache into program files directory while UAC enabled)

Apache Install to Program Files with UAC Enabled

4. After installing Apache you will see there’s a new icon installed on the System Tray (where the clock displayed in Windows), the new icon is called Apache Service Monitor, which is basically a tool to help you to Start/Stop/Restart Apache quickly and when you double click on it you’ll see this

Apache Service Monitor

Configuring PHP with Apache on Windows Vista / Windows 7

1. Create a new directory named PHP5 in C:\ so it’ll end up like below image for an example (you’re free to use other path, but if you choose to put it in different path, make sure to adjust them accordingly because in this guide i assume the PHP is extracted to C:\PHP5)

PHP Extracted to C:\PHP5

2. Find php.ini-production in C:\PHP5 and then rename it to php.ini

Rename php.ini-production to php.ini

3. Now you need to open php.ini using your favorite text editor (in this example i use notepad) and locate extension_dir directives and change the value into

"C:\PHP5\ext"

php extension_dir

4. Now you need to find output_buffering and change it to

output_buffering = Off

output buffering off

5. Find php_bz2.dll, php_mbstring.dll, php_mysql.dll, and php_mysqli.dll at the extensions section in php.ini and uncomment it (by removing the ; character)

Enabling php_bz2, php_mbstring, php_mysql and php_mysqli

6. Now we’ve finished configuring the php.ini, and so for the next step we’re going to run notepad as admin

Running notepad as admin

7. Now while running notepad as admin, you need to open C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf or C:\Apache2\conf\httpd.conf

Open httpd.conf as admin

8. After opening httpd.conf, locate and uncomment expires_module, headers_module, rewrite_module so you won’t have to enable them later because those three are perhaps the most commonly used apache modules especially the rewrite module and obviously you’re free to enable other modules you deemed necessary and when your done then add

LoadModule php5_module "c:/php5/php5apache2_2.dll"

Uncomment mod_expires, mod_headers, mod_rewrite, and add php5_module

9. Now you need to find this in httpd.conf

<IfModule dir_module>
DirectoryIndex index.html
</IfModule>

and replace with

<IfModule dir_module>
DirectoryIndex index.html index.htm index.php
</IfModule>

add directoryindex in apache

10. As for the next step, you need to locate (still in httpd.conf)

<IfModule mime_module>

and inside that directives, add:

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

php addtype to httpd.conf

11. Because Vista/7 UAC doesn’t allow you to create / edit files in Program Files directory, then the next step would be changing the root directory of your server from C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\ (default) into C:\htdocs. And to do this you’ll need to find:

DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"

and replace it with

DocumentRoot "C:/htdocs"

then find

<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs">

and replace it with

<Directory "C:/htdocs">

then find (inside the Directory directives)

AllowOverride None

and replace it with

AllowOverride All

Replacing htdocs, directory and allowoverride

12. Now you need to open System Properties and you can do this by pressing Windows Key + Pause/Break or by right clicking on My Computer then choose Properties, and then followed by clicking Advanced System Settings

Windows Vista System Information

13. At the System Properties, go to the Advanced Tab and then click on Environment Variables

Windows Vista Environtment Variables

14. Now you need to add PHPRC into System Variables, and to do this you just need to click on New at the System Variables section and then add

Variable name: PHPRC
Variable value: C:\PHP5

Add PHPRC

15. Still in Environment Variables, next you need to double click on Path under System Variables and then add

;C:\PHP5

Add PHP path

16. Now we’re done with the Environment Variables. The next step would be creating a directory named htdocs in C:\ (C:\htdocs) and then create a file named test.php inside that directory

create htdocs in c and then create test.php inside it

17. Open the test.php file you just created with notepad and add this line

<?php phpinfo(); ?>

18. Now we’re done with the PHP + Apache integration. Save your work and then restart your computer

19. Finally after finished with the booting process, now open your favorite browser (in this example i use Internet Explorer 7 which is the default browser for a freshly installed Windows Vista or if you’re running Windows 7 the default is IE8) and then type

http://localhost/test.php

Apache PHP Windows Vista done

And you’re done with Apache PHP integration process :) … now we’re going to continue with MySQL installation on Windows Vista / Windows 7

Installing MySQL on Windows Vista / Windows 7

1. For the first step you would need to run the MySQL Installer, then choose Typical setup type when asked to install it to default directory

installing mysql on vista

2. Continue with the installation process

mysql installation on vista

3. When you reached this screen after MySQL installation process finished, check Configure the MySQL Server Now and uncheck Register the MySQL Server now (but it’s up to you whether you want to register or not)

configuring mysql

4. When asked for the configuration type, choose Detailed (because you want better control obviously) ;)

detail mysql config on vista

5. Then choose Developer Machine as the server type to make sure MySQL doesn’t eat too much memory (well if you have plenty of RAM then feel free to choose other server type to suit your needs)

mysql server type

6. And then choose MultiFunctional Database when asked

mysql database type

7. When asked for the InnoDB storage location, choose C:\MySQL InnoDB Datafiles\ (but of course feel free to use different path if you want)

innodb path

8. And when asked for the max concurrent connection that MySQL would accept choose Decission Support (DSS)/OLAP (but if you think that you’re going to have many concurrent connection later especially if you’re running a popular WoW Private server then you can choose Manual Setting and choose the best value for your application, but make sure to not put a very high value)

max concurrent connection

9. When you reached the MySQL networking options, just leave it at default value

mysql networking options

10. As for the MySQL default character set, choose Best Support for Multilingualism to make UTF8 as the default charset

mysql default charset

11. And then when you reached Windows options, don’t forget to check Include Bin Directory in Windows PATH so you can access MySQL easily from the command line from anywhere

12. Now comes the most important part of the MySQL installation, and that is setting a root password for MySQL (root is the superuser in MySQL, make sure to remember root password and don’t give it to anyone else)

mysql root password

13. Now you’re done installing MySQL

mysql vista done

And you’re done installing Apache 2.2, PHP 5.3 and MySQL 5.1 on your Windows Vista / Windows 7 computer. Hopefully you enjoy this quick guide and of course if i missed / forgot something, please do let me know in the comment area below :)

Note: Updated because this guide can also be used on Windows 7, and also because from PHP 5.3.6 onward, they only release VC9 version which is not compatible with Apache binary from official Apache website

Comment?

Note: Comment may not appear right away.

139 comments on “How to Install Apache, PHP and MySQL on Windows Vista / Windows 7

  1. Hello.I followed your instructions and everything went right till installation of mysql.But when I click execute,It is showing error 0 cannot start mysql on windows.Please help.

    1. Could you paste the error log (the error log can be found by locating the datadir specified in my.ini file in your MySQL Installation Directory).

      For example if you install MySQL to C:\Program Files\MySQL .. the my.ini file is C:\Program Files\MySQl\my.ini (note this is just an example). And then open the my.ini file and locate the datadir location and then go to that location and open the .err file there and paste it into pastebin.com :)

  2. what do you mean with step 5 of install php? What should I do with those names in php.ini? remove, alter or replace?

    pls help me as you can

    1. php.ini commented that line by default (by placing semicolon ; in front of it). And all you have to do is remove the semicolon to enable those extensions (or any other extensions that you need)

  3. ok its me again, i managed to do it all, but i could only do the set up on the mysql, the others didnt have startes they came as RAR files which i extracted…any advice? and what do i do after this?

    1. Could you tell me where did you get the rar files you mentioned? because i just checked that (other than MySQL because you said you didn’t have any problem with it) … all the files (Apache and PHP) were compressed as zip files not rar files

  4. Awesome tutorials!
    Thank you so much!
    I installed apache2.2 and php5.3.
    Now can’t decide whether to install Oracle 10g express or MySQL. Any suggestion would be appreciated.
    Thanks again for the great tutorials.

    1. You’re welcome Javi. As for Oracle or MySQL, its depend on what applications / scripts you’re going to create or using :)

  5. Thank you so much for this amazing tutorial!!!
    I had problems with integration Apache and PHP via .msi files, great that you showed how to do it manually!
    Greetz!

  6. Right, lovely guide, but I stumble upon various issues too. I hope they can be resolved so I can continue my project.

    First, from the guide on how to compile mangos and scriptdev2: I do exactly the same as you, however when I choose to rebuilt a solution, it says: 1 compiled, 0 failed, 10 skipped. That’s not what it says on yours, on your screenshot they all succeed. Now I don’t know if this will cause errors for me later on (if it does, please do help?), but I do wonder why?

    Secondly, after installing apache and running the server, it says: running none of apache servers. Again, I don’t think that’s what supposed to happen.

    Finally, in the end it indeed errors: he can’t find localhost/test.php, even though all my configuration is the same as yours. Php does work though, because I’ve previousely tested it on other projects. That also means it can’t be the fault of my browser, IE9.

    My OS would be Windows 7, if that’s of any relevance.

    Thanks in advance.

    1. Hello Rai, and about your questions:

      1. If you get that many skipped messages on when compiling mangos, did you try to compile it as 64-bit executable? if yes, and you’re running Visual Studio Express, then you’ll need to change it to 32-bit (x86). Because the Visual Studio Express version can be used for 32 bit only :) (you’ll need to get the Pro or better version for 64-bit)

      2. Running none of apache server? what is the error message(s) when you start apache? or try opening the error.log file in your “Apache Installation Directory\logs”. Also based on my experience to those who’s having the same problem like you, the problem was caused by other process using the same listening port as Apache and that is port 80 (for example, Skype). The only solution for this is you need to change either the apache listening port or the other program that use port 80 to use different port

      3. Can’t find localhost/test.php? if you are sure that you’ve created it but still you get the not found message, try opening localhost/test.php.txt … and if you can see it in your browser that means, that you didn’t create a test.php file but you created test.php.txt file instead. This problem is caused when you saved your test.php file in Notepad and didn’t choose the save as type as all files so notepad append the .txt after .php. So the solution is when saving test.php file make sure to choose the save as type to all files :)

    2. Okay, compiling it for 32 bit does work. Shame it doesn’t for 64, but oh well.

      When attempting to start the apache server, it errors with: ‘the requested operation has failed’. In the error logs, it only says that the server starts up at port 80, which is good, and then the next line that it’s immediately requested to shut down by something. It doesn’t give any details.

      I am very much sure I’m working with a php file, and not a text document. I know that much. :D But I think that, as long as the apache server doesn’t run, this issue won’t be resolved. So maybe when apache works, this will too!

      Assuming I already have something that uses port 80 (not Skype, I don’t have that installed anymore), how to change Apache’s port?

    3. I’m sorry about that, because most people who’s having problem with test.php can’t be found is usually caused by notepad appending .txt extension right after the .php :)

      Anyway, if you need to compile as 64-bit executable you have to get Visual Studio Pro version (or better) which is not free :D

      As for apache problem, to see whether there’s another program using port 80, you can use this command

      netstat /aonp TCP | find /i "list"

      And you’ll get output similar to this

      TCP 127.0.0.1:80 0.0.0.0:0 LISTENING 3964

      That means process ID 3964 is using port 80.

      As for changing apache listen address you can find Listen 80 in httpd.conf and change it into something else you want :)

    4. The commandline indeed agrees that there are quite some other port-users. So I changed Apache’s listen to 81, but the same error still occurs. Should I try some other numbers, or do you have another solution or thought why it refuses to do its job?

    5. Same error as in?

      1. Apache process isn’t running (httpd.exe isn’t listed in task manager) even if you have changed it to listen at port 81

      Or

      2. When you type http://localhost/test.php you get a 404 not found message, or other error message and apache is running and listening at port 81

      Depending on which error you’re experiencing:

      1. If you’re having this problem that mean there’s another program using port 81 so you need to change apache to listen at different port or change the other program that is using that port to use another port

      2. If apache is listed in task manager (httpd.exe is running and listed in task manager) and listening at port 81 but you are unable to access it at http://localhost/test.php … you need to add :81 after the host name for example http://localhost:81/test.php because you’re not running the web server process at the default port :)

    6. httpd.exe doesn’t seem to be running. Strange, I’m quite certain it did work another time. But that aside, no, it doesn’t work. I tried switching the ports to pretty much all values between 1 and 200, none of them work and it can’t be that I use so many ports.

      The same error persist: when I open the apache service monitor, the dot on the left is red, whereas on your screenshot it is green. When I attempt to start up the service, thus making the dot green, it replies with “the request operation has failed!” and just does nothing, every single time I try it. I’ve re-checked all configuration, it is exactly the same as yours, and I’ve tried all those ports and whatnot.. :/

    7. Because httpd.exe isn’t running and port isn’t the problem here, try running below command from the command prompt:

      Note: make sure to adjust the path to where you installed apache

      "C:\Program Files\Apache Software Foundation\Apache2.2\bin\httpd.exe" -t

      Based from the output from the above:

      1. If you get Syntax error on line XX then you need to correct the problematic syntax on that line number

      2. If you get the Syntax OK message that means your httpd.conf file is correct, and the problem lies elsewhere, and i’d recommend you to disable php by commenting below lines in httpd.conf (just in case it was caused by the PHP binary), and then start apache, and if apache can start then that mean there’s a problem in your php binary like using non compatible version perhaps? :)

      # LoadModule php5_module
      # AddType application/x-httpd-php .php
      # AddType application/x-httpd-php-source .phps

    8. Aha, a syntax error indeed! The following line seems to be wrong:

      LoadModule php5_module “c:/php5\php5apache2_2.dll”

      It is one of the lines that’s from your guide. What’s so wrong about it?

    9. Actually it is written like below in the guide :) (using slash only)

      LoadModule php5_module "c:/php5/php5apache2_2.dll"

      But i’m suspecting that you’re using the VC9 version of php which is not compatible with HTTPD / apache built by httpd.apache.org binary

      The reason for that is because, i just checked the php website and apparently they (php team), no longer provide VC6 compile of the more recent version of PHP (the last version that is built using VC6 is PHP 5.3.5) and the newer version use VC9 which is compatible only with HTTPD binaries from apachelounge only. And when i wrote this guide back then, the php 5.3 listed on php website is compiled using VC6 but now they no longer list the VC6 version there anymore (unless you look at their releases archives)

      My suggestion to see if the problem was caused by php:

      1. Download PHP 5.3.5 http://windows.php.net/downloads/releases/archives/php-5.3.5-Win32-VC6-x86.zip

      2. Delete your PHP directory or rename the php directory into anything you want and then extract the newly downloaded php zip file into C:\PHP

      3. Start apache or test the config using httpd -t

      If it fixes the problem, there are two options for you to choose from :)

      1. Replace all the apache binaries into the apache binaries compiled by apachelounge.com and use VC9 compiled PHP binaries

      2. Or you still use the httpd binary from httpd.apache.org but you need to stick with php 5.3.5 or 5.2.x series (at least when i wrote this comment, i saw that the 5.3.6 onward is using VC9, in case they made a switch again later lol)

    10. That did it for now, thanks. :) As a result, finding php through localhost works as well now. Moving on to the next parts!

  7. Hi reaper-x,
    The tutorial on installing and configuring php & apache really saved my day. I tried out a number of forums but I was stuck trying to get Apache to restart. included the LoadMod dll you suggestet and there you have it. Thanks again. Will always refer here if I run into trouble in the future.
    regards
    Dee

  8. hello Reaper-X… again and again i use ur guides for a lot of things… u r great and i consider u my Mentor ;D, now i need ask u, is that possible to use sane guide for installing MySQL on vista as for windows 7?

    ty

  9. Reaper-X: First of all, thanks for the time and effort put into this amazing guide. Second, came late to your guide, and I wonder if you are still answering questions about it. I have installed Apache and PHP, going by the book, as per your guide, and I hit the same obstacle than many before me, once I got to “http://localhost/test.php”, with “This webpage is not available.” I double checked all the settings, both in Apache and PHP, and couldn’t find any different from your guide. I wonder, if you are still helping with your guide, if I could post you images of my configurations, both from Apache and PHP. Also, I couldn’t install MySQL, any time I tried, it tells me ‘The installation package could not be opened…etc’
    I understood the installation of Apache and PHP previous to MySQL were going to prepare the way for MySql getting installed without disabling UAC, but I was wrong. Please let me know if you could help me. My OS is Windows Vista Ultimate, and I run Privoxy as proxy, with Tor and I2P. Thank you very much, even if you can’t help, for your guide.

  10. I recently was given a template from a client to use in making his website. The template was created in India by associates there. For some reason, I can “edit” copy but when I go to “submit”, the screen turns white(blank). Once I go back to admin page again – it never saves, I just get a red “error” then all of the old text still there. HELP!!!!! What am I doing wrong? The client can save in his chrome browser but I cannot. I have windows Vista – but was told that shouldn’t make a difference. What do I need to do? It shouldn’t be this complicated. And even more, it’s making me look bad. Someone please email me an answer and soon….please.

  11. I have MySQL 5.1 Errors
    Errors that i got 2003;1043;1056

    i know what they are but MySQL cant do the last security check or apply

    And i lost the Password i know stupid of me that i lost the PW but know i cant reset it.
    Even System restore dosent help
    What should i do ?
    PLZ Help, if you can
    How can i reset my password and how can i install MySQL

  12. Hy installing apachi and php and the last thing http://localhost/test.php Butting in browser tells me only Error

    I did everything and checkt it but i saw that you have more files in PHP than i do but i have 5.3.3

    What is the problem i used internet exp and mozilla
    Yeah i have Windows7

    1. My problem is that if i rename the test file to test.php then i get 404 error if i just use test then i get white screen i used and / but nothing How do i check wheres my problem PLZ i need help
      The test file is php file
      How did i do that was easy with notepad there SAVE AS and but ALL FILES and test.php then it will become PHP file :)
      I dont know programing and i am dumb

    2. No need help i found my problem
      The problem was i saved as UNICODE not as ANSI and i solved my problem
      But THANX REAPER YOUR GUIDE IS VERY USEFULL
      IT WORKS ON WINDOWS 7

  13. When I prepare config(last screen) it crashes and says I need to put my firewall off(or allow it to connect) How can I solve this =.= Btw after I try to fix it it just keeps crashing without any reason

    1. I have MySQL 5.1 Errors
      Errors that i got 2003;1043;1056

      i know what they are but MySQL cant do the last security check or apply

      And i lost the Password i know stupid of me that i lost the PW but know i cant reset it.
      Even System restore dosent help
      What should i do ?
      PLZ Help, if you can
      How can i reset my password and how can i install MySQL

  14. I am having trouble setting up the PHP part of the guide. When i install PHP my install folder is missing alot of files you have in the first screenshot there. the file “php.ini-production” is not in there either. I went to the link to download PHP and downloaded the one you said to. Some help would be much appreciated

  15. heyy reaper iv followed alot of your guids and there immence, but how come i keep getting a “could not start the service mysql”? help please