Windows 7 - Installing - PHP, Apache HTTP, MySQL, phpMyAdmin on Windows

In this tutorial we will install PHP, Apache HTTP, MySQL and phpMyAdmin on Windows 7 with examples and explanations.
Note that it will work also on Windows XP and Windows Vista.

So we will install on Windows 7:

  • PHP 5.3.8

  • Apache HTTP Server (httpd) 2.2.21

  • MySQL Community Server 5.5.16

  • phpMyAdmin-3.4.5

Let's see, first of all, the list of official websites:

PHP: http://www.php.net/
The download page for the Windows binaries: http://windows.php.net/download/
Choose the version you want, we will take the VC9 x86 Thread Safe version, in the Zip format.

Apache HTTP: http://httpd.apache.org/
The download page: http://httpd.apache.org/download.cgi
We will take the Win32 Binary including Open SSL 0.9.8r (MSI Installer) version.

MySQL: http://www.mysql.com/
The download page: http://www.mysql.com/downloads/
We will take the Community Server version.
You do not need to enter your email address, just go at the bottom and click on: "No thanks, just take me to the downloads!".

phpMyAdmin: http://www.phpmyadmin.net
The download page: http://www.phpmyadmin.net/home_page/downloads.php
We will take the latest phpMyAdmin release version.

OK, let's see now our system:

We are supposed to install our software in the "Program files" directory, even PHP and phpMyAdmin (to remember where they are installed).
This is a very classic installation.

Apache HTTP

Lets' start with Apache HTTP.
Download the Win32 MSI installer with the link above.
Once done, you have to execute it (double click it).
Click Next, Accept and Next, then Next again.
You see now 3 empty fields that you have to fill.
In Network Domain, enter: localdomain
In Server Name, enter: localhost
In Administrator's Email Address enter a fake or a real address (it is not important for the moment).
Let the option "for All User, on Port 80, as a Service - Recommanded" ticked and click Next.
Choose the Typical installation then click Next.
Let the classic path as it is: "C:\Program Files (x86)\Apache Software Foundation\Apache2.2" and click Install.
Click Next then Finish.
Let's open a browser such as Firefox and write this in your address bar: http://localhost/
If you see "It works!" on the web page, so Apache HTTP is installed.

PHP

Let's continue with PHP.
Create a directory in "C:\Program files (x86)" named "php".
Create a new one inside "php" named "php-5.3.8".
So we have this new directory: "C:\Program files (x86)\php\php-5.3.8".
Download the Zip PHP file, open it and copy/paste all in the "php5.3.8" directory you have just created before.
PHP is installed.

Apache HTTP and PHP

At this point, we do not have finished the full installation. It is still missing MySQL and phpMyAdmin.
But we have to test before if PHP and Apache HTTP can work together correctly.

Open the httpd.conf file that you can find in this directory: "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf".
There are lot of lines starting with the LoadModule word.
Find them and write at the end of these LoadModule lines, this new one:

LoadModule php5_module "C:/Program files (x86)/php/php-5.3.8/php5apache2_2.dll"

We can also uncomment line 118 (or about) by removing the sharp # before:

LoadModule rewrite_module modules/mod_rewrite.so

Do the same at line 175 and remove the #:

ServerName localhost:80

We have now to add the php type.

Find the <IfModule mime_module> section.
At the end of it, just before </IfModule>, add this new line:

AddType application/x-httpd-php .php

Near line 224, we can see this:

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

Replace None by All, like this:

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All

Then let's add the DirectoryIndex for page named index.php.
Go at line 244 in order to find the <IfModule dir_module> line.
Modify balises like this:

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

Now file named index.php will replace the list of files at the root.

At this time, all our websites should have been created in the directory:

C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs

But it is not what we want.
We want to create our websites in another directory called:

C:\www

We have to find the line, generally at line 183:

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

Let's change it by:

DocumentRoot "C:/www"

We have also to change the line:

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

Indeed, let's replace it by the new directory:

<Directory "C:/www">

Be careful, the directory must exist or Apache HTTP will crash.

At the end of your httpd.conf file, add this line to tell to Apache where is the correct php.ini file (we will configure it in a minute):

PHPIniDir "C:/Program Files (x86)/php/php-5.3.8"

Go on your taskbar and left click on the Apache HTTP icon, click on Apache 2.2, then on Restart.
Now your http://localhost/ address will display all the files inside the "C:\www" directory or no one if the directory is empty.
If you do not have any error, let's continue.

Go on the "C:\www" directory.
Create a new file named test.php and open it.
Inside write this:

<?php
  phpinfo();
?>

Save it.
Reopen your browser at http://localhost/.
You can now see the file test.php.
Click test.php and normally you will see all features of your PHP installation.

It means that PHP and Apache are correctly installed.

Let's continue a bit with PHP, return to the directory:

"C:\Program Files (x86)\php\php-5.3.8"


Copy the php.ini-development file and rename it into php.ini.
Open this php.ini file and go until the Paths and Directories area (line 780).
Below find the line:

; extension_dir = "ext"

Remove the semicolon at the beginning of the line and replace the line by:

extension_dir = "C:/Program Files (x86)/php/php-5.3.8/ext"

Go now until the Dynamic Extension area (line 918).
You can see just below a block of lines starting with the ";extension=php_" expression.
If you want to activate an extension, remove the semicolon just before the line.
To our installation, let's decomment the lines:

extension=php_bz2.dll
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mysqli.dll

These extensions are respectively for compressing and extracting files on the fly, generating images, encoding characters, using MySQL.
If you prefer using mysql instead of mysqli, decomment the line:

extension=php_mysql.dll

If you do not know what it this, decomment both.

Others extensions can cause the crash of your Apache HTTP configuration if you decomment them without knowing what they are.
So, be careful when you choose to decomment them, try one by one and restart your server.
If it does not fail, it is OK.

We have now to set the Timezone correctly.
Of course, it depends of your country.
Go at line 1000 and remove the semicolon in front of line "date.timezone =".
Add the timezone of your choice, for example:

date.timezone = "America/Los_Angeles"

if your server is installed in the West cost.
And use

date.timezone = "Europe/Paris"

for a server in France.

OK save this php.ini file and restart the Apache HTTP server.
Let's come back to the test.php file at the root of our server ("C:\www") to see the new features appear.
Indeed, now the timezone is correctly set and we can see the new extension such as bz2, gd, mbstring and mysqli.

MySQL

Let's install MySQL now.
Execute the MSI file (double click on it).
Click Next, Accept the terms of the Licence Agreement, Next, Complete, Install.
A new window appear, click Next and Next.
You come back to the last window and a Checkbox is checked, let it checked and click Finish to launch the MySQL Instance Configuration Wizard.
This wizard opened, click on Next.
Choose Detailed Configuration and Next.
Choose Developer Machine and Next.
Choose Multifunctional Database and Next.
Let the standard configuration: C: and Installation Path.
Click Next.
Choose the Manual Setting and write the number of simultaneous connections you want then click Next.
Let all checked and the Port Number 3306.
Click Next.
Choose Best Support for Multilingualism then Next.
Select Install As Windows Servive with Service Name MySQL, let the option Launch the MySQL Server automatically selected and select also the Include Bin Directory in Windows PATH option.
Click Next.
You have now to choose a password, type it and retype it, then click Next.
Your username is root by default.
You will have to use it in your phpMyAdmin application, or by a command line tool.
Click Execute.

If you have an error at step 3: Could not start the service mysql, it is because who already have a version of MySQL on your computer.
Generally go on the hidden "C:\ProgramData" directory or "C:\Users\YourName\AppData\Roaming".
If you can not see it, open a folder and click on the Organize button at the top left.
Then click the View tab, find the "Show hidden files and folders" option and select it.
Click OK.
Now your hidden files are displayed.
Come back to your "C:\ProgramData" directory or "C:\Users\YourName\AppData\Roaming".
If you can see the MySQL directory and that you have directories inside, rename this MySQL directory into MySQL_Save for example, and try again the installation.
Try also to remove and reinstall MySQL.
Normally it will be enough.
So MySQL is now installed.

phpMyAdmin

Let's install phpMyAdmin.
Nothing hard, just open the phpMyAdmin-3.4.1-all-languages.zip file you downloaded before.
Copy all files in a new directory named phpmyadmin into "C:\www".
Open your browser at http://localhost/phpmyadmin/
You will see the connection page of phpMyAdmin.
Enter your login and password and click GO,
Click the SQL icon on the top left, just under the phpMyAdmin logo.
A window open, click Import files.
Select the file: C:\www\phpmyadmin\scripts\create_tables.sql.
Click GO.
You just created the phpmyadmin database, useful for advanced features.
You have now to create the user and their rights to use it.
Reclick the SQL icon under the logo, and write in the window:
GRANT SELECT, INSERT, DELETE, UPDATE ON `phpmyadmin`.* TO 'pma'@localhost IDENTIFIED BY 'pmapass';
Click GO.
Nothing happens apparently but you finished the phpMyAdmin installation.
If all is OK, you will be able to manage your MySQL database.

Creating an alias

1. host

Now we will create an alias for our project.
Instead of write this address:

http://localhost/site/ourproject/

we will use:

http://ourproject/

Open the file "C:\Windows\System32\drivers\etc\hosts".

Inside there are a comment and several lines beginning by:

127.0.0.1

Normally you have already:

127.0.0.1 localhost

Write just under this:

127.0.0.1 ourproject

Save the file.

2. httpd.conf

Now open your httpd.conf, for example:

C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf

Uncomment (remove the sharp # before) the line 470 where there is this line:

Include conf/extra/httpd-vhosts.conf

Save the file.

3. httpd-vhosts.conf

Open the httpd-vhosts.conf file, for example you can find it in your Apache path:

C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\extra

Do not remove anything inside, just add this at the end of the file:

# ourproject
<VirtualHost *:80>
    ServerAdmin me@ourproject
    DocumentRoot "C:/www/ourproject"
    ServerName ourproject
    ServerAlias ourproject
    ErrorLog "logs/ourproject.error.log"
    CustomLog "logs/ourproject-access.log" common
</VirtualHost>

Then add this code too, it is necessary to see the localhost:

# localhost
<VirtualHost *:80>
    ServerAdmin webmaster@dummy
    DocumentRoot "C:/www"
    ServerName localhost
    ServerAlias localhost
    ErrorLog "logs/localhost.error.log"
    CustomLog "logs/localhost-access.log" common
</VirtualHost>

Save the file.

Create a file named index.php in the "C:\www\ourproject" directory and write this:

<? php
  echo "Eh it works :D";
?>

Save the file.

Now restart your Apache HTTP server.

Go to this address:

http://ourproject/

And normally you are seeing:

Eh it works :D

Well done, you made it! cool

Comments

Comment: 

BadproG,

Thanks a lot mate I've used this tutorial and it works for me there's just some inconsistency on the directory spelling which caused the setup to fail but correcting those made it work.

Cheers.

LiNo

Comment: 

Hello LiNo,

Indeed I saw an error in the DocumentRoot variable,  and i fixed it.

Thank you cool

BadproG

Comment: 

It s all good only those mispelled directory paths missing space on "Program Files (x86)".
Just also would like to add that I also loaded expiresmodule in my case as I was using expiresactive on some of my htaccess files.

Cheers

Comment: 

I made it to:      Open your browser at http://localhost/phpmyadmin/

 there i was able to login, i did what asked, but then after i did all the changes in :

Creating an alias  , nothing works, i can`t connect to http://localhost/   or   http://localhost/phpmyadmin/

 .I don`t know what went wrong, helpppppp

Otherwise, it was the best tutorial i ever followed

Thanks

 

Comment: 

Hello Denis806,

Thank you for your comment.

Indeed, I forgot to mention the virtual host for localhost.
Read again the 3rd part of the Create an alias (3. httpd-vhosts.conf).
I made some modifications to explain how to use it wink

I hope it will be OK.

Comment: 

Slight Problem,

Everything went fantastically smoothly and I even sorted out that problem with the MySQL installation where it won't start the service, however have run into 2 snags.

1) I hit step 4 on the MySQL installation and it comes up with error 1045 - Access Denied for 'root'@'localhost' (using password:YES).

2) I thought that it may not matter about that step 4 so clicked on the skip part as I've read you can manually configure your password later on, however the next bit when I install PhpMyAdmin - it tells me the mysql extension is missing! I've been through the php.ini file and done a few things suggested on other sites but none of it seems to work!

Any ideas anybody? Any help would be much appreciated!

Thanks in advance

Dave (Geordie from the UK)

 

Comment: 

Hello Dave,

1.

Do you have the directory MySQL in one or both of these paths:

  • "C:\ProgramData"
  • "C:\Users\YourName\AppData\Roaming"

If yes, rename it or them, and retry an fresh installation of MySQL.

It seems that your problem is MySQL is not installed correctly on your computer, because phpMyAdmin can not find it.

I think your first problem is linked with this one.

2.

Did you remove the semicolon before

extension=php_mysqli.dll

or/and

extension=php_mysql.dll

If yes, that's ok, if not do it.

3.

Put a password when you reinstall your MySQL software.
Just add a letter, for example "a", to set a password.

4.

Which version of Windows 7 do you have?
Professional 64bits?

5.

Do you have a software that can use MySQL as well?
If yes, uninstall it.

 

Try all these things and tell me if your problem is still there.

Cu

Comment: 

I stuck! please help me..my apache can not restart..I try to follow all these step..but stuck on configuring php..

"Go on your taskbar and left click on the Apache HTTP icon, click on Apache 2.2, then on Restart."

but its fail to restart. I checked all the spelling, but my apache still not working..i cant sleep :(

please help me.

Comment: 

Hello skwlsgelf,

I prefer to help you here (maybe some people have the same problem).
Look into your error.log file.
You can find it there (where you installed Apache HTTP):
C:\Program Files (x86)\Apache Software Foundation\Apache2.2\logs\error.log.

Can you copy/paste it there please?

Comment: 
here the "error.log" with "httpd.conf -(edited)" let me know if you want to see my httpd.conf.
apache running without a problem with original httpd.conf..
when i switched to httpd.conf (edited) its fail to restart. thanks!
 
here you go..if you found some error..please let me know..thanks you very very very much :)
 
Starting the Apache2.2 service
The Apache2.2 service is running.
rmine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[Sat Dec 10 23:34:57 2011] [notice] Apache/2.2.21 (Win32) configured -- resuming normal operations
[Sat Dec 10 23:34:57 2011] [notice] Server built: Sep  9 2011 10:26:10
[Sat Dec 10 23:34:57 2011] [notice] Parent: Created child process 3920
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[Sat Dec 10 23:34:58 2011] [notice] Child 3920: Child process is running
[Sat Dec 10 23:34:58 2011] [notice] Child 3920: Acquired the start mutex.
[Sat Dec 10 23:34:58 2011] [notice] Child 3920: Starting 64 worker threads.
[Sat Dec 10 23:34:58 2011] [notice] Child 3920: Starting thread to listen on port 80.
[Sat Dec 10 23:35:10 2011] [error] [client 127.0.0.1] File does not exist: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/favicon.ico
[Sat Dec 10 23:44:43 2011] [notice] Parent: Received shutdown signal -- Shutting down the server.
[Sat Dec 10 23:44:43 2011] [notice] Child 3920: Exit event signaled. Child process is ending.
[Sat Dec 10 23:44:44 2011] [notice] Child 3920: Released the start mutex
[Sat Dec 10 23:44:45 2011] [notice] Child 3920: All worker threads have exited.
[Sat Dec 10 23:44:45 2011] [notice] Child 3920: Child process is exiting
[Sat Dec 10 23:44:45 2011] [notice] Parent: Child process exited successfully.
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[Sat Dec 10 23:44:51 2011] [notice] Apache/2.2.21 (Win32) configured -- resuming normal operations
[Sat Dec 10 23:44:51 2011] [notice] Server built: Sep  9 2011 10:26:10
[Sat Dec 10 23:44:51 2011] [notice] Parent: Created child process 1948
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[Sat Dec 10 23:44:51 2011] [notice] Child 1948: Child process is running
[Sat Dec 10 23:44:51 2011] [notice] Child 1948: Acquired the start mutex.
[Sat Dec 10 23:44:51 2011] [notice] Child 1948: Starting 64 worker threads.
[Sat Dec 10 23:44:51 2011] [notice] Child 1948: Starting thread to listen on port 80.
[Sun Dec 11 00:03:29 2011] [notice] Parent: Received restart signal -- Restarting the server.
[Sun Dec 11 00:03:29 2011] [notice] Child 1948: Exit event signaled. Child process is ending.
httpd.exe: Syntax error on line 129 of C:/Program Files/Apache Software Foundation/Apache2.2/conf/httpd.conf: Cannot load C:/Program Files/php/php-5.3.8/php5apache2_2.dll into server: The specified module could not be found.  
[Sun Dec 11 00:03:30 2011] [warn] (OS 995)The I/O operation has been aborted because of either a thread exit or an application request.  : winnt_accept: Asynchronous AcceptEx failed.
[Sun Dec 11 00:03:31 2011] [notice] Child 1948: Released the start mutex
[Sun Dec 11 00:03:32 2011] [notice] Child 1948: All worker threads have exited.
[Sun Dec 11 00:03:32 2011] [notice] Child 1948: Child process is exiting
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 10.129.141.168 for ServerName
[Sun Dec 11 18:55:43 2011] [warn] pid file C:/Program Files/Apache Software Foundation/Apache2.2/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Sun Dec 11 18:55:43 2011] [notice] Apache/2.2.21 (Win32) configured -- resuming normal operations
[Sun Dec 11 18:55:43 2011] [notice] Server built: Sep  9 2011 10:26:10
[Sun Dec 11 18:55:43 2011] [notice] Parent: Created child process 364
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 10.129.141.168 for ServerName
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 10.129.141.168 for ServerName
[Sun Dec 11 18:55:43 2011] [notice] Child 364: Child process is running
[Sun Dec 11 18:55:44 2011] [notice] Child 364: Acquired the start mutex.
[Sun Dec 11 18:55:44 2011] [notice] Child 364: Starting 64 worker threads.
[Sun Dec 11 18:55:44 2011] [notice] Child 364: Starting thread to listen on port 80.
[Sun Dec 11 19:01:09 2011] [error] [client 127.0.0.1] File does not exist: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/exports, referer: http://website
[Sun Dec 11 19:05:27 2011] [error] [client 127.0.0.1] File does not exist: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/exports, referer: http://website
[Sun Dec 11 19:11:28 2011] [notice] Parent: Received restart signal -- Restarting the server.
[Sun Dec 11 19:11:28 2011] [notice] Child 364: Exit event signaled. Child process is ending.
httpd.exe: Syntax error on line 129 of C:/Program Files/Apache Software Foundation/Apache2.2/conf/httpd.conf: Cannot load C:/Program Files/php/php-5.3.8/php5apache2_2.dll into server: The specified module could not be found.  
[Sun Dec 11 19:11:29 2011] [warn] (OS 995)The I/O operation has been aborted because of either a thread exit or an application request.  : winnt_accept: Asynchronous AcceptEx failed.
[Sun Dec 11 19:11:29 2011] [notice] Child 364: Released the start mutex
[Sun Dec 11 19:11:30 2011] [notice] Child 364: All worker threads have exited.
[Sun Dec 11 19:11:30 2011] [notice] Child 364: Child process is exiting
 

Comment: 

skwlsgelf,

No problem, I am sure we will find the solution of your epic fail. smiley

  1. Can you tell me what is your OS and where is installed your PHP version please?
  2. Do you have a software such as Skype, already running on port 80?
  3. Where is your root directory? It is C:\www for example in the tutorial.
  4. Are you testing this installation on a local computer or directly from a remote server?
  5. Can you also copy/paste your httpd.conf please.

 

Comment: 

dude, my apache is ok now..sorry, my own mistake..later i'll install and configure mysql and phpmyadmin..will let you if I got any errors during installation..thank you very very much!

Comment: 

Hey can you please tell me what was the error..and how did you fix it..I am geting the same error..

Thanks

Comment: 

hi

I got problem in Apache HTTP and PHP installation

the problem is that I'm not able to save the httpd.conf file

it shows error that "you can't replace existing file , access denied"

please somebody help me...

Thanks..!

Comment: 

Hello krunal,

What is your Operartor System and which version?

Comment: 

I had a problem with loading mysql and mysqli extensions

extension=php_mysql.dll
extension=php_mysqli.dll

even though uncomented the lines in php.ini file, these extensions didn't load

SOLUTION
1. Right click on my computer and choose properties
2. Click on Advanced system settings
3. On Advanced tab find button Environment Variables and click on it
4. In System variables click on PATH varibale and click button edit
5. Append the path of your php folder (separate paths with ; symbol)
   I did like so:      ; C:\php
6. Click OK ok ok ok save it, restart your machine and problem will be solved

I hope that will help someone save some time

Comment: 

Hello Award,

In your case you used C:\php because, I think, you installed PHP in this directory.
To avoid confusion, in the turorial, it's C:\Program Files (x86)\php\php-5.3.8.

This problem appears sometimes because Windows doesn't know where to find the PHP directory.
Once you've filled the Environment variables with the PHP directory, Windows is able to find it.

Thank you for the trick. cool

Comment: 

If you have an error at step 3: Could not start the service mysql, it is because who already have a version of MySQL on your computer.

In order to sort it out I had to do following:

 

To open a Windows command window with administrator right:

  • Select Start up menu -> Command Prompt -> (Right Click) -> Run as Administrator
  • If the Command Prompt is not there, select Start up menu -> type cmd -> select cmd.exe on the top -> (Right Click) -> Run as Administrator

Commands require administrator right will be documented as:

admin>

Pre-Installation

To set the desktop development environment to a known clean state, remove older version(s) of MySQL.

Remove old MySQL Windows Service

  1. Control Panel -> Classic View -> Administrative Tools -> Services
  2. If MySQL exists,
    1. Stop the MySQL Service if it is running
    2. Open a Windows command window with Administrative Right
    3. Delete the service
      admin> sc delete MySQL
      
    4. Reboot the machine

Remove old MySQL installation(s)

  1. Verify whether MySQL has been installed. Control Panel -> Control Panel Home -> Programs -> Uninstall a program
  2. If any version(s) of MySQL Server exists, uninstall the MySQL installation(s)
  3. Delete the directory where the older version(s) of MySQL is installed

Comment: 

It work for me now =)

Thanks for great tutorial

Comment: 

Award,

Great explanation!
MySQL and Windows could be a nightmare at times.
I'm sure it will help.

Thank you very much. laugh