In order to complete our combo of Linux, Apache, PHP, and MySQL, we still need the PHP language interpreter. PHP is a recursive acronym that expands to PHP:Hypertext Preprocessor. It has been in development for several years now; the versions most commonly used are Version 3 and Version 4. We will use PHP4 for this chapter, as it was the most current stable version at the time of this writing.
Some Sample PHP
One of the nice things about PHP is that PHP code can be entered
directly into HTML code. The web server will pass everything between
?> to the PHP
module, which will interpret and execute the commands. Here is a very
simple example for some PHP code in an HTML page; if you already have
set up PHP, you could run this directly from your web server (if not,
we’ll tell you how to set up PHP below):
<html> <body> <?php echo "Hi,"; ?> LAMP enthusiasts. </body> </html>
As you probably already have expected, your browser will output the following text:
Hi, LAMP enthusiasts.
This extremely simple example shows how Apache works together with
the PHP interpreter: the code in
?> is passed to the PHP interpreter, which
echo command, which in turn outputs
its parameters to the web browser. In addition to this, the line
LAMP enthusiasts is simply added as ordinary
HTML text (and since it doesn’t have any markup, it
doesn’t look like HTML).
Of course, PHP can do much more. Like most programming languages, it can use variables and make decisions, as in the ...