Apache and PHP Install
Apache and PHP Install
trial and error. Learn the tricks you'll need to get started with our guide.
Apache 2 and PHP are popular (and cheap!) choices for creating interactive Web sites.
Installing Apache 2 by itself under Windows is easy, but installing PHP 4 so it runs
without restrictions with Apache 2 is tricky.
It doesn’t help that the PHP 4.3 manual’s Windows installation section is silent on
installing PHP to work with Apache 2, and the section on Apache 2 installation is missing
a lot of the information you need. Other published installation guides contain errors as
well, leaving some installers to resort to trial-and-error methods, such as replacing PHP’s
DLLs with those from another PHP version. But instead of spending hours of frustration
trying to figure it all out, you can follow our simple guide through the maze.
If you have an earlier version of Apache 2 installed and running, bring it down and
uninstall it before installing your new server. Multiple versions of Apache 2 cannot
coexist.
Double-click the Apache 2 .msi file. After agreeing to the license, you’ll be presented
with the dialog box shown in Figure A.
Figure A
Set the Network Domain and Server Name to something appropriate (e.g., localhost
works fine assuming you aren’t installing Apache onto a remote computer), enter your e-
mail address in the Administrator’s Email Address field, and leave the port 80/service
option radio button selected. Selecting a Typical installation in the next dialog will
provide a no-hassles working install.
Installation tip
I recommend changing the default installation directory from C:\Program Files\Apache
Group to C:\Apache, or something similar that fits the 8.3 filename format. Doing so will
keep you from ever having to write quotes around the path to your Apache installation.
After a few moments, the Installation Wizard will tell you that Apache 2 is installed. The
only thing left to do is test it by opening your browser and browsing to localhost. You
should then see the default Apache 2 Web page.
You can then delete all the sample files in your main Web server directory, which by
default is C:\InstallDirectory\Apache\Apache2\htdocs. If you have an Index.html to copy
here, do so, or you can create a barebones file for yourself. For the HTML uninitiated, the
following code will work fine:
<html>
<head>title=default server page</head>
<body>Default server page</body>
</html>
Unfortunately, the Windows Event log is not a very convenient tool for debugging
installation settings. It is much more satisfactory to test Apache server loading in a
command line window, where you see error reports right away. So, after making the
configuration changes I’m about to discuss, open up a command line window, navigate to
Apache’s binary directory (C:\InstallDir\Apache2\bin), and start Apache from there.
To enable Apache processing of PHP pages, remove the comment character (#) so that
the line reads:
Installing PHP
Although you can download PHP’s source, you’ll want to start out with the binaries as
you did with Apache. Apache 2 can run PHP programs in two ways: via a CGI interface
using Php.exe or internally (and faster) using PHP’s DLLs. So, for every PHP version
released, there are two Windows binary packages. The smaller of the two, an .msi
package, installs the CGI executable Php.exe but is missing the modules you need to run
PHP scripts via Apache DLLs. The larger .zip package contains those, and you’ll want to
grab them from the Win32 section of the snaps.php.net Web site. After downloading the
file, unzip it to C:\Php, preserving folder names. Unless you just like flying blind, you
will also want the PHP manual, which is available in a variety of languages.
doc_root = c:\apache\apache2\htdocs
extension_dir = c:\php\extensions
session.save_path = c:/temp
You can use a forward or backward slash for the session.save_path. The PHP manual
says these path arguments need trailing backslashes, but it’s incorrect. In PHP 4.3, that is
not the case. You’ll need to create C:\Temp if it doesn’t already exist.
The next step is to enable Apache to run PHP programs as modules, which involves two
steps. First, copy C:\Php\Php4ts.dll to your Windows system folder. Look for the
LoadModule section in Httpd.conf and add this line:
To find out whether Apache loads, enter this in the command-line window you already
opened:
apache –k start
apache –k restart
The advantage of starting Apache from a command line is that if there is an error, Apache
will report it immediately. The problem you’re most likely to have if things don’t work
will be that Apache cannot load Php4apache2.dll for some reason. If you see Apache
complaining with this error, try retracing your steps to ensure that you entered all settings
as I described above.
To find out whether Apache is processing PHP pages correctly, use your text editor to
create a simple PHP page, called Phptest.php, containing the following line:
Tags: apache | guide | install | installing | php | together | tricks | windows | work
Related Links