Setting up a Test Bench Web Server With Apache, PHP, MySQL, and More on Windows

40
March 27, 2010 // Web Development

Create a Website Directory

This is the directory in which your websites will be stored.

  1. Create the main directory (“C:/websites”)
  2. Create a subdirectory for each website (“C:/websites/example”)
  3. Create a subdirectory for the live website content (“C:/websites/example/online”)

Install Apache

  1. Go to Apache’s main website: www.apache.org
  2. Under Apache Projects, click the link that says “HTTP Server”
  3. Download the “Win32 Binary including OpenSSL” from the latest stable release.  At the time of this document, it was version 2.2.9.
  4. Locate the downloaded file and double click on it to launch the installation wizard.
  5. A “Welcome to the Installation Wizard” will appear.  Click “Next”.
  6. Accept the terms of use. Click “Next”.
  7. A notice will appear. Click “Next”.
  8. You will be prompted to enter in your server’s information.  Fill in the following:
    • Network Domain: localhost
    • Server Name: localhost
    • Administrator’s Email Address: admin@example.com
  9. Select “for All Users, on Port 80, as a Service – Recommended”.
  10. Click “Next”.
  11. Select “Typical” setup type. Click “Next”.
  12. The install path should look like:
    C:\Program Files\Apache Software Foundation\ApacheX.X\
    Click “Next”.
  13. Click “Install”.
  14. Wait for installation to complete. Click “Finish”.
  15. Go to http://localhost and make sure it displays “It works!”.

Install PHP

  1. Go to PHP’s main website: www.php.net
  2. Click on the “downloads” link, located at the top of the page.
  3. Download the latest PHP installer. At the time of this document, it was “PHP 5.2.6 installer”.
  4. Locate the downloaded file and double click on it to launch the installation wizard.
  5. A “Welcome to the PHP X.X.X Setup Wizard” will appear.  Click “Next”.
  6. Accept the terms of use. Click “Next”.
  7. The install path should look like:
    C:\Program Files\PHP\
    Click “Next”.
  8. Select the Apache Webserver that you had installed.  In my case, it was “Apache 2.2.x Module”. Click “Next”.
  9. Set the location of the Apache Configuration Directory.  It should be:
    C:\Program Files\Apache Software Foundation\Apache2.2\conf\
  10. The next screen will ask you what items you want to install.  Expand the “Extensions” section and click the arrow next to “MySQL”. Select “Entire feature will be installed on local hard drive”. Click “Next”.
  11. Click “Install”.
  12. Wait for installation to complete. Click “Finish”.

Configuring and Testing both Apache and PHP

  1. Configure Apache
    • Go to:
      C:\Program Files\Apache Software Foundation\Apache2.2\conf
    • Open “httpd.conf” in Notepad.
    • Replace the line:
      DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
      With:
      DocumentRoot "C:/websites/example/online"
    • Replace the line:
      <Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs">
      With:
      <Directory " C:/websites/example/online">
    • Replace the line:
      DirectoryIndex index.html
      With:
      DirectoryIndex index.html index.php
    • Add the following lines to the top of the file:
      AddType application/x-httpd-php .php
      AddType application/x-httpd-php-source .phps
    • Search for the line:
      # AllowOverride controls what directives may be placed in .htaccess files.
      Replace this line (which should be below the line you just searched for):
      AllowOverride None
      With:
      AllowOverride All
    • Click File -> Save.
    • Click File -> Exit.
  2. Configure PHP
    • Go to:
      C:\Program Files\PHP
    • Open “php.ini” in Notepad.
    • (Optional Step) Replace the line:
      upload_max_filesize = 2M
      With:
      upload_max_filesize = 10M
    • (Optional Step) Replace the line:
      post_max_size = 8M
      With:
      post_max_size = 20M
    • (Optional Step) Replace the line:
      short_open_tag = Off
      With:
      short_open_tag = On
    • (Optional Step) Replace the XXX on the line with your ISP’s SMTP server, YYY:
      SMTP = XXX
      With:
      SMTP = YYY
      Example:
      SMTP = mail.earthlink.net
  3. Create 1st PHP file:
    • Go to:
      C:\websites\example\online
    • Create a file called “phpinfo.php” and open it with Notepad.
    • Enter in:
      <?php
      phpinfo();
      ?>
    • Click File -> Save.
    • Click File -> Exit.
  4. Restart Apache
    • Click Start->Programs->Apache HTTP Server X.X->Control Apache Server->Restart.
  5. Test that Apache and PHP are Correctly Configured

Install MySQL

  1. Go to MySQL’s main website: www.mysql.com
  2. Click on the “Downloads” link, located at the top of the page.
  3. Click the “Download” button for the “MySQL Community Server”.
  4. Select “Windows”
  5. Download the “Windows ZIP/Setup.EXE” (at the time of this document it was “mysql-5.0.67-win32”). Note: You may need to register an account to download it.
  6. Extract the zip file and run “Setup.exe”
  7. A “Welcome to Setup Wizard for MySQL Server X.X” will appear.  Click “Next”.
  8. Select “Typical”. Click “Next”.
  9. Click “Install”.
  10. Click “Next”.
  11. Click “Next”.
  12. Select “Configure the MySQL Server now”. Click “Finish”.
  13. A Configuration Wizard will appear. Click “Next”.
  14. Select “Detailed Configuration”. Click “Next”.
  15. Select “Developer Machine”. Click “Next”.
  16. Select “Multifunctional Database”. Click “Next”.
  17. Select “C:” drive and “Installation Path”. Click “Next”.
  18. Select “Decision Support (DSS)/OLAP”. Click “Next”.
  19. Select “Enable TCP/IP Networking”. Set Port Number to: 3306. Select “Enable Strict Mode”. Click “Next”.
  20. Select “Standard Character Set”. Click “Next”.
  21. Select “Install As Windows Service”. Select “Launch the MySQL Server automatically”.  Select “Include Bin Directory in Windows PATH”. Click “Next”.
  22. Enter the new root password (twice): “example”. Click “Next”.
  23. Click “Execute”.
  24. Click “Finish”.

Configure Apache, PHP, and MySQL together

  1. Copy “libmysql.dll” from:
    C:\Program Files\PHP
    To Both:
    C:\WINDOWS\system
    And:
    C:\WINDOWS\system32

Supplemental Install – phpMyAdmin

  1. Go to phpMyAdmin’s main website:  www.phpmyadmin.net
  2. Click on the “DOWNLOADS” link at the top of the page.
  3. Download the latest release’s “english.zip”.
  4. Create a directory called “phpmyadmin” in “C:/websites”
  5. Extract the contents of english.zip to “C:/websites/phpmyadmin”
  6. Create a file “config.inc.php” inside the main phpmyadmin directory.  The main directory might resemble:
    C:\websites\phpmyadmin\phpMyAdmin-3.0.1-rc1-english
  7. Open “config.inc.php” in Notepad.
  8. Paste in the following data:
    <?php
    /*
    * This is needed for cookie based authentication to encrypt password in
    * cookie
    */
    $cfg[‘blowfish_secret’] = ‘a8bcFQp98fs8d'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! *//*
    * Servers configuration
    */
    $i = 0;

    /*
    * First server
    */
    $i++;

    $cfg[‘Servers’][$i][‘user’] = ‘root';
    $cfg[‘Servers’][$i][‘password’] = ‘example'; // Your MySQL Password

    /* Authentication type */
    $cfg[‘Servers’][$i][‘auth_type’] = ‘config';
    /* Server parameters */
    $cfg[‘Servers’][$i][‘host’] = ‘localhost';
    $cfg[‘Servers’][$i][‘connect_type’] = ‘tcp';
    $cfg[‘Servers’][$i][‘compress’] = false;
    /* Select mysqli if your server has it */
    $cfg[‘Servers’][$i][‘extension’] = ‘mysql';
    /* User for advanced features */
    $cfg[‘Servers’][$i][‘controluser’] = ‘root';
    $cfg[‘Servers’][$i][‘controlpass’] = ‘example'; // Your MySQL Password
    /* Advanced phpMyAdmin features */
    $cfg[‘Servers’][$i][‘pmadb’] = ‘phpmyadmin';
    $cfg[‘Servers’][$i][‘bookmarktable’] = ‘pma_bookmark';
    $cfg[‘Servers’][$i][‘relation’] = ‘pma_relation';
    $cfg[‘Servers’][$i][‘table_info’] = ‘pma_table_info';
    $cfg[‘Servers’][$i][‘table_coords’] = ‘pma_table_coords';
    $cfg[‘Servers’][$i][‘pdf_pages’] = ‘pma_pdf_pages';
    $cfg[‘Servers’][$i][‘column_info’] = ‘pma_column_info';
    $cfg[‘Servers’][$i][‘history’] = ‘pma_history';

    /*
    * Directories for saving/loading files from server
    */
    $cfg[‘UploadDir’] = ”;
    $cfg[‘SaveDir’] = ”;
    ?>

  9. Go to:
    C:\Program Files\Apache Software Foundation\Apache2.2\conf
  10. Open “httpd.conf” in Notepad.
  11. Change:
    #Include conf/extra/httpd-vhosts.conf
    To:
    Include conf/extra/httpd-vhosts.conf
  12. Replace the line:
    DocumentRoot “C:/websites/example/online”
    With:
    DocumentRoot “C:/websites”
  13. Replace the line:
    <Directory “C:/websites/example/online”>
    With:
    <Directory “C:/websites”>
  14. Click File -> Save.
  15. Click File -> Open.
  16. Select the file “httpd-vhosts.conf” located at:
    C:\Program Files\Apache Software Foundation\Apache2.2\conf\extra
  17. Paste the following:
    NameVirtualHost *:80
    # —————————————–
    #localhost
    <VirtualHost *:80>
    DocumentRoot “C:/websites/example/online”
    ServerName localhost
    <Directory “C:/websites/example/online”>
    AllowOverride All
    Options Indexes FollowSymLinks
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>
    # —————————————–
    #example.local
    <VirtualHost *:80>
    DocumentRoot “C:/websites/example/online”
    ServerName example.local
    <Directory “C:/websites/example/online”>
    AllowOverride All
    Options Indexes FollowSymLinks
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>
    # —————————————–
    #phpmyadmin.local
    <VirtualHost *:80>
    DocumentRoot “C:/websites/phpmyadmin/phpMyAdmin-3.0.1-rc1-english”
    ServerName phpmyadmin.local
    <Directory “C:/websites/phpmyadmin/phpMyAdmin-3.0.1-rc1-english”>
    AllowOverride All
    Options Indexes FollowSymLinks
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>
    # —————————————–
  18. Click File -> Save.
  19. Open the file “hosts” located at:
    C:\WINDOWS\system32\drivers\etc
  20. Paste the following contents into the file:
    127.0.0.1     localhost
    127.0.0.1     example.local  # Example
    127.0.0.1     phpmyadmin.local     # phpMyAdmin
  21. Click File -> Save.
  22. Restart Apache.

Supplemental Install – Eclipse PDT (PHP Development Tools)

  1. Go to PDT’s main website:  www.eclipse.org/pdt
  2. Click “Downloads” on the left navigation pane.
  3. Download the Windows “All-In-One”.
  4. Unzip the contents of the zip file to:
    C:\Program Files\pdt
  5. The main executable, “eclipse.exe”, will be within the directory:
    C:\Program Files\pdt\eclipse
  6. If it does not run, it is most likely because you do not have Java installed. Download and install the latest version of Java at:
    www.java.com

Supplemental Install – Additional Web Browsers

  1. For testing purposes, we recommend downloading the following web browsers:

About the author

40 Comments

  1. Finally, my first post…

  2. Scottie Linen May 3, 2010 at 7:57 am

    Interesting review. I got to your site with google while i was researching for web hosting services. I will turn over your site to my friends and I am sure they will think the same about your writing on this site.Cheers

  3. I am unquestionably bookmarking this page and sharing it with my acquaintances. You will be getting plenty of visitors to your website from me!

  4. finally someone laid it all out there, thank you

  5. Install Apache – 15.Go to http://localhost and make sure it displays “It works!”.
    Yes it works…

    Configuring and Testing both Apache and PHP – ?Go to:
    http://localhost/phpinfo.php

    I’m stuck… httpd-2.2.15-win32 and php-5.2.13-win32 on a Vista x64 machine
    Can anyone help, please?

    Paul S.

  6. It seems that a RESTART fixed all my problems…

  7. I am trying to follow this on Win7 but getting stuck with restarting the Apache service after I change the httpd-vhosts.conf file.

    I get the following error:
    DocumentRoot must be a directory.

    I have full access to all the files and I copied and pasted everything.

    any thoughts?

  8. Paul Sauve: Glad to hear it worked!
    Kenn: Can you send in a snippit from the httpd-vhosts.conf file that you added?

  9. Here is what i have for the vhosts file. I have tried comenting things and deleting things, but no joy. Currently it bombs at line 47 (did not include headers) which is the first dodumentroot statement.

    NameVirtualHost *:80

    #
    # VirtualHost example:
    # Almost any Apache directive may go into a VirtualHost container.
    # The first VirtualHost section is used for all requests that do not
    # match a ServerName or ServerAlias in any block.
    #

    ServerAdmin webmaster@dummy-host.localhost
    DocumentRoot “C:/Program Files/Apache Software Foundation/Apache2.2/docs/dummy-host.localhost”
    ServerName dummy-host.localhost
    ServerAlias http://www.dummy-host.localhost
    ErrorLog “logs/dummy-host.localhost-error.log”
    CustomLog “logs/dummy-host.localhost-access.log” common

    ServerAdmin webmaster@dummy-host2.localhost
    DocumentRoot “C:/Program Files/Apache Software Foundation/Apache2.2/docs/dummy-host2.localhost”
    ServerName dummy-host2.localhost
    ErrorLog “logs/dummy-host2.localhost-error.log”
    CustomLog “logs/dummy-host2.localhost-access.log” common

    # —————————————–
    #localhost

    DocumentRoot “C:/websites/example/online”
    ServerName localhost

    AllowOverride All
    Options Indexes FollowSymLinks
    Order allow,deny
    Allow from all

    # —————————————–
    #example.local

    DocumentRoot “C:/websites/example/online”
    ServerName example.local

    AllowOverride All
    Options Indexes FollowSymLinks
    Order allow,deny
    Allow from all

    # —————————————–
    #phpmyadmin.local

    DocumentRoot “C:/websites/phpmyadmin/phpMyAdmin-3.3.4-all-languages”
    ServerName phpmyadmin.local

    AllowOverride All
    Options Indexes FollowSymLinks
    Order allow,deny
    Allow from all

    # —————————————–

  10. Kenn: The first thing I would do is delete the VirtualHost examples (it might be giving you a problem). Theoretically, you should be able to copy and paste everything from step 17 into httpd-vhosts.conf (replacing everything that was previously in the file). Keep me posted.

  11. Just went through the process again with a literalword for word copy of your instructions.

    I still get the two errors firing below. I am going to try it on a xp build i have for this pc and see if it plays nice.

    Thanks for the great write up and the follow up.

    The Apache service named reported the following error:
    >>> DocumentRoot must be a directory

    The Apache service named reported the following error:
    >>> Syntax error on line 5 of C:/Program Files/Apache Software Foundation/Apache2.2/conf/extra/httpd-vhosts.conf:

    Line 5 is the DocumentRoot line.

  12. Jesse, Do you think it is a version problem. The downloads I found are a few versions past this article.

  13. Holy Handgrenades I found the problem!!!

    Apperently from me coping and pasting from the website to notepad and then into the config file the Quotation Marks around the DocumentRoot were morfied into a different type of quote mark. Long story short the test system is on a closed network and I can not access interwebz on my test system. so somewhere those marks got hosed.

    This is the link to the forum post that clued me into it. Hope this helps any one else that follows.

    http://hardforum.com/showthread.php?p=1035796734

  14. Kenn: I’m glad you got it up and running! Thx for posting your solution.

  15. Pingback: Log 20100701 « The Ric Wise Blog

  16. 1. Thanks for providing this wonderful information – in a few short hours I’ve resolved installing WAMP that’s been frustrating me for over a month.

    2. I concur with Paul and Kenn – a restart/reboot was required and the copy paste foobars the quotation marks.

    3. Cheers!

  17. Hi, when I try to save the changes that I make in the httpd.conf file in the conf folder, it won’t let me. How can I fix this?

  18. Nevermind, it had to do with the security settings on my own computer!

  19. I am running windows 7. I completed the installation process, but when I start Apache, I get the following error message:

    httpd.exe: Could not reliably determine the server’s fully qualified domain name, using 192.168.1.20 for ServerName
    (OS 10048) Only one usage of each socket address (protocol/network address/port) is normally permitted. : make_socket: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down
    Unable to open logs

  20. Hi Kip, not sure if you did the supplemental install…but try the following:
    Open httpd.conf and edit the “ServerName” directive. It should read, “ServerName localhost” Make sure the “Listen” directive is set to “Listen *:80″.

    Let me know if you have any luck with that.

  21. In httpd.conf, I removed the “#” from in front of the ServerName so that it now reads “ServerName localhost:80″. I also changed “Listen 80″ to “Listen *:80″. The changes solved part of the problem, but I still have the following error message:

    “(OS 10048) Only one usage of each socket address (protocol/network address/port) is normally permitted. : make_socket: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down”

  22. Hi Jesse, thanks for a great tutorial.

    After step 20 “Supplemental Install – phpMyAdmin” I ran into trouble”. Now I cant start Apache. MSDOS pops up saying “DocumentRoot Must Be a directory”

    Only thing that I did that differed from the tutorial was that “libmysql.dll” did not exist so I tried copying “libpq.dll” instead.

    Also when the tutorial said “Paste in the following data:” I wasnt sure whether or not to replace the samlpe data in the files. First I didnt and got the error message, then I did and still got the errormessage, only relating to a different folder.

    Please help :)

  23. Looks like you are trying to bind to port 80 which is already in use by another process. Try running netstat uility on commandline, to see who is using port 80.

    netstat is builtin in windows.

    you can try using another port like 8080 for testing, this changes the way you access the website in a browser.
    instead of writing http://localhost/
    now you have to write
    http://localhost:8080/

  24. Kip,

    As Amrit pointed out, you probably have another process on port 80. Typical programs that listen on port 80 can be:
    Skype or some antivirus software.

    The way to correct this:
    A) Shutdown the program that’s using port 80
    B) Configure that software to use a different port
    C) Configure Apache to listen on a different port with the Listen directive in httpd.conf. If antivirus software is being used, configure the antivirus software to allow Apache to bind on the port you have chosen.

    Way to diagnose which app, if any, has bound to port 80:
    1) Open Command Prompt
    2) Enter “netstat -no -p tcp” without quotes
    3) In the second column, look for “:80″ next to an IP address. Then, look at the last column (PID), which will contain the process ID that is associated with it.
    4) You can then kill that process in task manager. This is only a temporary fix if you kill the process (since it will most likely start when your computer is restarted).

  25. Andreas,

    Please past your DocumentRoot lines in a comment so that I can take a look at it. As the error states, you most likely do not have it pointing to the correct directory.

    libpq.dll is a PostgreSQL DLL and is not the correct one. I would go back through the steps and make sure you download the correct packages.

    And yes, “Paste in the following data:” was intended to mean overwrite ALL contents in the file.

  26. pls can i used wamp 4 php instead of downloading php. Mysql, phpmyadmin or is it compusory 2 dwnload it one after d other

  27. Is there perhaps a mistake.
    It says
    Copy “libmysql.dll” from:
    C:\Program Files\PHP

    I found no such .dll there, but I did find the .dll in my MySQL folder.

    Also I didn’t get the first test after installing Apache to work, until after I altered the hosts file as mentioned here.
    Open the file “hosts” located at:
    C:\WINDOWS\system32\drivers\etc
    Paste the following contents into the file:
    127.0.0.1 localhost

  28. Amaka, WAMP is a package that automates the majority of the process I go over in this writeup. You are welcome to use it, however making modifications via WAMP is out of the scope of my writeup. The purpose is of my article is to explain how you can do it on your own and how you can configure it properly to handle multiple PHP projects on your local machine.

  29. Dave,

    I’ll have to look into the libmysql.dll issue. Did the rest of the tutorial work out for you?

    Typically the “hosts” file comes populated with “127.0.0.1 localhost”. So I’m surprised you had to manually do that.

    – Jesse

  30. No other problems than I mentioned Jesse, thanks a lot btw :) .
    Previously in my hosts file was:
    ::1 localhost

    I searched for it, and some said it was for IPv6, but whatever, localhost works now and didn’t before.

    Everything else that I used is working, although tbh I haven’t installed myphpadmin yet as I don’t need it for my brothers site that I am working on atm.

  31. Hi Jesse.. It is a good doc for everyone interested in this field. If possible can u pls forward this to my email

  32. Pingback: Digital Review

  33. Pingback: Digital Review

  34. I am currently reading on MySQL and my question is. To do my practices do i need to install only MySQL from their webside and this will serve as my Webserver or i should first install for exemple Wampserve, which also has MySQL or is this different?

  35. Pingback: Digital Review

  36. In the line:
    ” …
    /* Select mysqli if your server has it */
    $cfg[‘Servers’][$i][‘extension’] = ‘mysql’
    …”

    should the second line be:
    “…
    $cfg[‘Servers’][$i][‘extension’] = ‘mysqli’
    …”
    ?

    Thanks for your work.

  37. Hi Jesse!
    Thanks for your explanations!
    Everything wents well until I reach the point: “Configuring and Testing both Apache and PHP”, point 5…
    When I try to open the http://localhost/phpinfo.php, the message is: FORBIDDEN, You don’t have permission to access /phpinfo.php on this server.
    How can I fix this problem???
    Thanks in advance & best regards

    yura2

  38. I have installed mysql 5.5. for wndow 7 64 bit. And the installation process was completed sucessfully. After that, i run the command line and after executing a command. The system starts 2 hang. Then i uninstalled it, and again installed it. But the problem remains.
    Then i downloaded mysql 5.1. And installed it after uninstalling mysql 5.5.Bt still the problem remains.
    Can anyone help ???

  39. …or you could just download WAMP and it’ll do the job :) http://www.wampserver.com/en/

    Not taking credit away! Great job :) Thanks a lot :)

  40. Pingback: PHP page doesn’t load. Instead it gives me a 404 error

Leave a Comment


*