Install & Configure Apache with PHP, JSP, MySQL, and PHPMyAdmin on Windows 2000/XP

Revision 6
Jeff Lundberg - contact@jefflundberg.com
http://jefflundberg.com/

Feedback · Trackback URL

Introduction:

This is a quick guide to install and configure the Apache web-server with PHP and JSP support on a Windows XP Pro SP2 machine. Let me know if this helps you out! Feedback is appreciated. This is my first “published” guide. I made it for my own reference. Why not share? Did you find this guide useful? I appreciate feedback.

Versions used:

Windows XP SP2
Apache 2.0.52
PHP 5.0.3
Tomcat 5.5.4
Java 2 Standard Edition 5.0
MySQL 4.1.7
MyODBC Connector/ODBC 3.51.10
PHPMyAdmin 2.6.0, patch level 3

Change Log:

2005.01.09 Jeff Lundberg
  • Minor update to include other firewalls
  • PHP 5.0.3 update - libmysql.dll and libmysqli.dll have been merged to libmysql.dll.
2004.12.17 Jeff Lundberg
  • Converted to HTML
  • Minor fixes to inconsistencies.

2004.12.16

Jeff Lundberg

  • Updated to PHP 5.0.3
  • Fixed PHP mysql module problems
  • Fixed PHPMyAdmin
  • Updated some screenshots

2004.11.24

Jeff Lundberg,
Mark Gearhart

  • Upgraded all versions.
  • Updated Tomcat installation Instructions (thanks to Mark Gearhart for some updates).
  • Verified everything works with Windows XP SP2. (except mysql support in PHP!)
  • New screenshots – now featuring Firefox.
  • Reverted back to WinXP. Still works in 2000.

2003.08.18

Rob Garry
rob.garry@bentley.com

  • Changed workers.properties file
  • Used mod_jk2 connector
  • Updated version numbers
  • Using Windows 2000 instead of XP. (C:\WINDOWS becomes C:WINNT)

2002.08.01

Jeff Lundberg,
Andrew Conrad,
Rick Reumann,
Dallas Thunder

  • Changed workers.properties file – the ajp14 stuff was removed
  • Modified php.ini.

2002.07.31

Jeff Lundberg

  • Modified workers.properties file – some paths were for older versions of Tomcat

2002.07.26

Jeff Lundberg

  • Modified step 5 of JSP install - hardcoded the Tomcat
    configuration into the Apache httpd.conf file.
  • Also added MySQL installation instructions.

Download the Components

Before you can begin, you must first download all the required components. The components used in this tutorial are listed below. You may want to download the latest versions. The versions used in the tutorial have been verified to work.

Apache Web Server

PHP

JSP

MySQL

  • MySQL Database
    • http://dev.mysql.com/downloads/mysql/
    • Download the latest stable release for Windows
    • mysql-4.1.7-win.zip
  • MyODBC
  • PHPMyAdmin

Note to Windows 2000 users:
This guide should work with Windows 2000 as well. Remember to replace C:\WINDOWS with C:\WINNT anywhere in this document.

Apache

  1. Run apache_2.0.52-win32-x86-no_ssl.msi







  2. Fill in the information and choose “for All Users, on Port 80, as a Service -- Recommended” when prompted.











  3. Finish the installation program.



  4. If you have Windows Firewall enabled, select Unblock on the Windows Security Alert.  Zone Alarm will also popup a message. For any firewall, make sure port 80 is open.



  5. Test: Open http://localhost in a web browser. If you see something like that following, you’ve just successfully installed Apache!

PHP

  1. Extract php-5.0.3-Win32.zip into C:\php



  2. Copy and rename c:\php\php.ini-recommended to c:\php\php.ini
    Note: Before, we used to copy php.ini to the C:\WINDOWS directory. This is not required with the Apache “PHPIniDir” directive pointing to c:\php.

  3. Open php.ini and change the following and then save it.

    include_path = ".;C:\php\includes\"
    session.save_path = "C:\Temp"
    session.cookie_path = \
    doc_root = "C:\Program Files\Apache Group\Apache2\htdocs"
    extension_dir = "C:\php\ext\"
    extension=php_mysql.dll
    extension=php_mysqli.dll
    mysql.default_port = 3306
    mysql.default_host = localhost
    mysql.default_user = root
    mysqli.default_port = 3306
    mysqli.default_host = localhost
    mysqli.default_user = root

  4. Add C:\php to your PATH System Environment Variable.
    • Right-click on My Computer and choose Properties.
    • Select the Advanced tab.
    • Click Environment Variables.
    • Under System variables, select “Path” and choose Edit.
    • Move the cursor to the end of the string and add ;C:\php.
      • A basic path will look something like the following
        %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\php

  5. Note: If you don’t want to add C:\php to your path, you may copy libmysql.dll to your C:\Windows\System directory.

  6. Add the following lines to httpd.conf:
    Note: httpd.conf is located in C:\Program Files\Apache Group\Apache2\conf\

    LoadModule php5_module "c:/php/php5apache2.dll"

    AddType application/x-httpd-php .php

    PHPIniDir "C:/php"

  7. Change the following line in the httpd.conf.
    Note: If you don’t plan on adding JSP support, don’t add index.jsp.

    From:
    DirectoryIndex index.html index.html.var

    To:
    DirectoryIndex index.php index.jsp index.html index.html.var

  8. Test: Restart Apache & open http://localhost in a web browser. Hopefully you see the same thing as before.

    Hint: To quickly restart Apache, simply left-click (once) on the Apache system tray icon.





  9. Test: Create a new text file called phpinfo.php. Paste the following into it.

    <?php phpinfo();?>

    Save the document under C:\Program Files\Apache Group\Apache2\htdocs. Now open http://localhost/phpinfo.php in a web browser. You should see something like the following:



  10. Test: To check if the modules are loading correctly, scroll down. If the modules are working, you should see a section for “mysql” and “mysqli”.

JSP

  1. Run jre-1_5_0-windows-i586.exe









  2. Run jakarta-tomcat-5.5.4.exe.





  3. Select service to have Tomcat automatically startup when Windows starts.

    Note: If you want to run some tests later, install the Examples as well. The examples allow you to test everything to make sure it’s all working properly.





  4. Type in some admin password you can remember. Leave it on port 8080.







  5. Click Finish.



  6. Test: Start Tomcat. If you chose Run Apache Tomcat on the previous screen, it will start automatically.



    You should see two icons in your system tray at this time.

    Open http://localhost:8080/ in a web browser. You should see something like the following:



  7. Extract mod_jk2.so from jakarta-tomcat-connectors-jk2.0.4-win32-apache2.0.49.zip to
    C:\Program Files\Apache Group\Apache2\modules.
  8. Add the following to the "Load Modules" section of your Apache http.conf file

    LoadModule jk2_module modules/mod_jk2.so

  9. Create a new text document called workers2.properties. Save this document in the following directory:
    C:\Program Files\Apache Group\Apache2\conf. Put this text into the file:

    [shm]
    file=C:\Program Files\Apache Group\Apache2\logs\jk2.shm
    size=1048576

    [channel.socket:localhost:8009]
    port=8009
    host=127.0.0.1

    [ajp13:localhost:8009]
    channel=channel.socket:localhost:8009

    [status:status]

    [uri:/jsp-examples/*]
    worker=ajp13:localhost:8009

    [uri:/status/*]
    worker=status:status

  10. Add the following to the end of the jk2.properties file located in
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\

    handler.list=channelSocket,request
    channelSocket.port=8009
    channelSocket.address=127.0.0.1

    Note: Always start Tomcat first and then start Apache. If you have to bounce Tomcat, remember to take down Apache first and restart it after Tomcat restarts.

  11. Test: Begin by shutting down both Apache and Tomcat. Start the Tomcat service. Open http://localhost:8080/ in a web browser. You should see something like the following:



    If you installed the examples, test out the JSP Examples as well as the Servlet Examples to make sure they work. If they do not work, something is wrong with your Tomcat installation. (It’s much easier to stop the Tomcat service, uninstall it, and start over again. Troubleshooting this is not fun as there’s little documentation available.)

  12. Test: Start up the Apache2 service and open http://localhost/ in a web browser. Still working?

  13. Test: Now try http://localhost/phpinfo.php to make sure that’s still in working order.

  14. Final Test: Open http://localhost/jsp-examples/ in a browser, you should see something like the following:

MySQL

  1. Run setup.exe from mysql-4.1.7-win.zip.



















  2. Enter a root password, confirm it, and then click Next >.







  3. Test: Open a command prompt and navigate to C:\Program Files\MySQL\MySQL Server 4.1\bin\ Type in the command

    mysqlshow -u root -p

    Enter the password you supplied earlier. It should display the current databases.

MyODBC

  1. Run MyODBC-3.51.06.exe.
    Note: Installing MyODBC is optional.











  2. Click Finish.

PHPMyAdmin

  1. Extract phpMyAdmin-2.6.0-pl3.zip to your htdocs directory and rename it to something like “phpmyadmin” (e.g. C:\Program Files\Apache Group\Apache2\htdocs\phpmyadmin).

    Note: You may want to use a .htaccess file or use the following to prevent random people from accessing PHPMyAdmin.

  2. Open the config.inc.php (in the phpmyadmin directory) in your favorite text editor and modify the following variables:

    $cfg['PmaAbsoluteUri'] = 'http://localhost/phpmyadmin/';

    $cfg['Servers'][$i]['extension'] = 'mysqli';

    $cfg['Servers'][$i]['auth_type'] = 'http';

  3. Open http://localhost/phpmyadmin/ and login using “root” (password is whatever you set it to earlier).

 

Congratulations!!!

 

 

Resources

Apache

http://www.apache.org/

PHP

http://www.php.net/

Perl

http://www.perl.com/
http://www.activestate.com/

JSP

http://www.acg-gmbh.de/mod_jk/
http://www.galatea.com/flashguides/apache-tomcat-24-win32.xml
http://www.jguru.com/faq/view.jsp?EID=853905

MySQL

http://www.mysql.com/
http://www.phpmyadmin.net/

Other

http://www.experts-exchange.com/

Special Thanks!

Special thanks to Andrew Conrad, Rick Reumann, Dallas Thunder, Andrei Isakov, and Mark Gearhart for their helpful feedback.