Apache-PHP-MySQL on Win32 R R



The combination of Apache/PHP/MySQL (the formidable trio) puts power in your hands as a web builder. You depart from building static webpages to making your site interactive, all at a price you can't beat - free.

My configuration is, Apache 1.3.22, PHP 4.0.6, MySQL 4.0.0.

A few options exist for configuring these three applications to work together. phptriad, and foxserv both provide a single package that installs and configures apache, mysql, and php on your Windows machine. You can also do the installation manually. I prefer manual installation, because it gives me the greatest flexibility as to how and where I want my the installation.

Downloads

Make a directory on your desktop. Call it SERVERS.
Download all the softwares below and save them in the servers directory you created.

Windows 95 users

Windows 98 users

Windows NT 4.0 Users

Windows ME/2000/XP Users

  • See additional softwares below

Additional Softwares

Creating Directories

Create the following installation directories

  • C:\apache
  • C:\mysql
  • C:\php

Just a word of caution! If you prefer to install any of the programs in a different directory, you can do so, but note the following important points:

  1. Remember to use the proper directory in all the installation procedures from this point on. So if you choose to install in D:\ drive for example, each time I mention C:\, you must change that to D:\. I won't remind you about this anymore :)
  2. Whatever directory you choose to install in, must not have a space in the name. For instance, you will encounter problems if you choose to install in c:\program files\...
.

With those two points in mind, let's move on.

Installations

In c:\windows\desktop\servers,

Windows 95 users

  • Double click and install the Winsock 2 update
  • Double click and install instmsi.exe
  • Double click on dcom98.exe and install it.
  • If you're asked to restart your computer, do so. Then come back here to continue with the intallations.
  • See additional Installations below.

Windows 98 users

  • Double click and install instmsi.exe
  • Double click on dcom98.exe and install it.
  • If you're asked to restart your computer, do so. Then come back here to continue with the intallations.
  • See additional Installations below.

Windows NT users

  • Double click and install instmsi.exe
  • If you're asked to restart your computer, do so. Then come back here to continue with the intallations.
  • See additional Installations below.

Windows ME/2000/XP users

See additional Installations below.

Additional Installations

If you encounter problems with the installations, see the troubleshooting section below.

If your connection to the Internet is through dial-up, then you already have TCP/IP networking installed. This is required for apache to work.

However, if you need to install TCP/IP

  • Click on Start/Settings/Control Panel
  • Double click on Network icon
  • Click on Add
  • Click on Protocol
  • Click on Add
  • Click on Microsoft
  • Click on TCP/IP in the right window
  • Click on OK
  • Restart your computer when you're asked to.

In c:\windows\desktop\servers,

  • Apache: double click on apache_1.3.22-win32-x86.msi, and the installation wizard will start.
    • Choose c:\apache as the installation directory.
    • When you're asked for your domain, enter it if you have one. Otherwise, enter localhost.
    • Choose to let apache run as a service if you want it to start each time your computer starts. That way, apache will run transparently in the background.
  • MySQL: double click on MySQL-4.0/mysql-4.0.1-alpha-win.zip. Choose c:\mysql as the installation directory. Accept all defaults, unless you know what you're doing, and have a reason to change things.
  • PHP: double click on php-4.0.6-Win32.zip. Unzip all the files to c:\php. There's nothing to install here.

Troubleshooting

If you encountered problems in the installation process, visit http://www.apache.org/dist/httpd/binaries/win32/TROUBLESHOOTING.html for troubleshooting ideas.

We are going to look at how to configure apache using httpd.conf; php using php.ini; and mysql using my.ini.

Configuring Apache

The behavior of your apache server is controlled by one file called httpd.conf located in C:\Apache\conf directory.

Apache should already be configured and ready to go.

Configuring PHP

There are two ways to set up PHP to work with Apache on Win32 platform. One is to use the CGI binary (php.exe), the other is to use the Apache module php4apache.dll.

I tried both setups and I found the module option a whole lot easier to configure. Plus, it runs smoother without errors like $PHP_SELF showing /php/php.exe/scriptname.php.

  • Use Notepad to open c:\php\php.ini-dist. Another config file is called php.ini-optimized. Don't use that for now. It has some global variables turned off. If you like, you can take a look at it on your own once your php installation is successful.
  • Change:
    extension_dir = ./

    to:
    extension_dir = "c:\php\extens~1"

    Avoid making typos. So double check what you've typed.

    Save the file as C:\Windows\php.ini. Note that php.ini must be saved in C:\windows, even if you chose to install php in a different directory. This is important!

  • Move c:\php\php4ts.dll to c:\windows\system (for Windows 9x/Me), or to winnt/system32 (for Windows NT/2000/XP). Overwrite any old php4ts.dll that may be present. Just like php.ini, php4ts.dll must be in you OS's system folder.
  • With Notepad, open c:\apache\conf\httpd.conf
  • Add the following three lines at the bottom of httpd.conf file:

    LoadModule php4_module c:/php/sapi/php4apache.dll

    AddType application/x-httpd-php .php .php3 .php4 .phtml

    AddModule mod_php4.c

  • Also do the following:

    Look for

    <IfModule mod_dir.c>
        DirectoryIndex index.html
    </IfModule>
    
    Replace it with
    
    <IfModule mod_dir.c>
        DirectoryIndex index.html index.php index.php3
    </IfModule>
    
  • Save httpd.conf
  • Use Notepad to open c:\windows\hosts.sam or c:\windows\hosts. You should only have one of these files at a time in your windows directory.
  • make sure there's a line in it that says

    127.0.0.1 localhost

    If this line is missing, add it at the bottom of the file OR

  • if it has a # in front of it, remove the #, ie. replace

    #127.0.0.1 localhost

    with

    127.0.0.1 localhost

  • save the file.

Testing Apache and PHP

  • Open a dos console. cd to c:\apache
  • Issue the command apache -k start.
  • Open Notepad
  • Type the following into it

    <?php phpinfo(); ?>

  • Save it as test.php in c:\apache\htdocs
  • Lauch your browser
  • Type into the address bar, the following:

    http://localhost/test.php

  • If all went well, you should get a whole lot of information about your php and apache configuration!
  • If you get any errors, go over the configuration steps again very carefully.

Configuring MySQL

I already have the configuration process written in my Intro to MySQL. Since the configuration guide is comprehensive, I'm not gonna repeat it here. So click here to go there.

Loading Additional PHP Modules

Certain modules are already built into Apache. MySQL for instance, is already built into Apache server, which means mysql will work without requiring you to configure apache in any way.

Many other modules however, require modules to be loaded before they can work with apache. These modules are in the form of Windows DLLs.

To load additional DLLs , it is possible to use the Apache directive LoadFile. In this case, it is no more necessary to copy the DLL to the system directory.

For example if you wanted to add the GD image module,

In C:\WINDOWS\PHP.INI, look for the line

extension_dir = "D:\php\extens~1"

Under that, add

extension=php_gd.dll

In D:\APACHE\CONF\HTTPD.CONF, add this to the bottom of the file:

LoadFile c:/php/extens~1/php_gd.dll

That adds the gd functionality to php. Repeat the same steps in php.ini and httpd.conf, to add more modules.

Each time you do this, remember to reload apache with the command apache -k restart.

If you have any dl() statements in your scripts, comment them out, otherwise apache will give errors.

Phew! That was a long one. If everything worked for you, Congratulations! Now the sky is the limit to what you can produce or reproduce with your new powerful Open Source installation.

Document Root

Your $DOCUMENT_ROOT will be c:\apache\htdocs.

So place all your web files and folders in this directory. Including html and php files.

Problems?

How to Uninstall Apache

Double click on the installation file apache_1.3.22-win32-x86.msi, and choose the uninstall option. This will remove the system installation, but retain your data directory /htdocs. You have to remove the data directory manually.

Links

User Comments (under construction)

Error in query