Adding PHP to Apache on Linux
Supercharging Your Web Pages

Ken Coar
Thursday, December 23, 1999 07:46:09 AM
Editor's note: With this debut column, Ken Coar
joins LinuxPlanet as a monthly columnist. Coar's background as a pioneer in the
open-source community is impressive, as a member of the Apache Group and a
director and vice president of the Apache
Software Foundation. He is also a core member of the
Jikes
open-source Java compiler project, a contributor to the
PHP project, the author of
Apache Server for Dummies,
and a contributing author to Apache
Server Unleashed.
The technology that supports the Web continues to evolve, and one of the
latest mutations involves capitalising on its very user-driven interactivity.
The days of all-static content are past; the Web has evolved to a point at
which many sites actually remember personal preferences for each of their
(potentially millions) of visitors. News sites may display stories in only
those categories you find interesting; online music stores can provide you with
listings of new works sorted in order by your favourite artists; Web search
engines can learn to implicitly restrict the types of content they'll list for you. The
possibilities are endless, and the key is generating a unique presentation for
each viewer.
There are a number of ways of accomplishing this, from the primitive
fly-swatter capabilities provided by "server-side includes" to the tactical nuke
Extra Strength features found in application servers. The PHP scripting
language falls somewhere into the middle ground, supplying phenomenal
capabilities for free.
What is PHP?
PHP is a scripting language, with a particular affinity for and
emphasis on enhancing Web pages. It has a syntax very similar to C (with a
smattering of Perl and shell), and includes lots and lots of functions for
things like database access, dealing with CGI requests, and image creation and
manipulation.
When PHP is used as an Apache module, and the language elements are embedded
in the document pages themselves, the HTML file might look something like the
following:
<head>
<?
//
// Preload all the functions and other definitions we need.
//
include("$DOCUMENT_ROOT/scripts/definitions.php3");
$pdetails = lookup_visitor();
echo " <title>WhizBang Products: Welcome back, "
. $pdetails["first_name"] . "!</title>\n";
?>
</head>
<body bgcolor="#ffffff">
<h1 align="center">Super-Duper Whizbang Products</h1>
<h2 align="center">Welcome back,
<? echo $pdetails["first_name"] . " "
. $pdetails["last_name"]; ?></h2>
When a Web client requests a PHP-enabled page, the mod_php
module gets to interpret the document and make changes to it before the Web
server itself sends the results back. The results of the above PHP fragments
might cause the following to be what the Web client actually receives:
<head>
<title>WhizBang Products: Welcome back, Ken!<title>
</head>
<body bgcolor="#ffffff">
<h1 align="center">Super-Duper Whizbang Products</h1>
<h2 align="center">Welcome back, Ken Coar</h2>
Notice how all the stuff between "<?" and
"?>" was replaced—interpreted by
mod_php—before it reached the browser? That's part of
the power of PHP.
Next: Assumptions in This Article »