Web Server Programming
Chapter 6
PHP
You can download your PHP from the PHP home site. I have not included direct links to the downloads; the PHP site is mirrored and you should download from the mirror that is closest to you - the links to the mirror sites are on the download page at php.net. (As noted in the section on Apache, you can download a bundle with Apache, PHP, and MySQL for Windows from Hotscripts.) You will of course need the PHP documentation. This is available in many languages, with on-line and downloadable versions. Currently, only HTML documentation is available (the older PDF manual is "out of print"). It is likely that the documentation will eventually all be in the form of XML documents with alternative XSL programs for generating both HTML and PDF versions; so you may find that a PDF version is again available soon.
Cygwin and Linux users probably have a version of PHP included in their
releases (maybe not the most up to date version but one that should be adequate
for learning exercises). Although on the system, these PHPs are most likely
not integrated into the Apache that is also installed.
There are instructions for Unix/Linux (and Windows)
at the PHP site.
alternative explanations are at the PHP tutorial
site associated with O'Reilly publishers,
and in the tutorials at the Site Wizard.
(You may find configuring your
PHP-Apache the hardest part of using PHP.) A Cygwin system most likely includes
a PHP component in a subdirectory of the /release directory; this
contains a precompiled .dll and a shell script that has to be run
to complete installation. Essentially, you have to copy the PHP .dll
into the library subdirectory used by Apache and then "rebase" your .dlls.
The Apache httpd.conf configuration file must also be updated.
The following instructions will give you a working PHP with Windows and Apache. These instructions do NOT define the way to fully configure a PHP-Apache combination that allows safe and correct operation on the Internet. They represent a quick hack that lets you get started quickly running your own Windows-Apache, and accessing it via a browser aimed at localhost.
C:\tmp1\php-4.3.1-Win32\php4ts.dll into C:\PHP.C:\tmp1\php-4.3.1-Win32\sapi\php4apache.dll into C:\PHP (there are
two "apache" files, one for 1.3 series and the other for 2 series
Apaches; use the right one).C:\tmp1\php-4.3.1-Win32\extensions\php_gd.dll int C:\PHP.C:\tmp1\php-4.3.1-Win32\php.ini-dist and
save it as php.ini in the appropriate Windows directory
(appropriate? depends which flavor of Windows - probably C:\Windows
for 98/ME/XP, or C:\winnt for others).php.ini file (any editor, Notepad will do but make sure
it doesn't save the edited file as php.ini.txt). The minimum changes
that you must make are:
; Directory in which the loadable extensions (modules) reside. extension_dir = C:\php(there will be some other initial setting for
extension_dir).extension=php_gd.dll and uncomment it..dll file
from the extensions folder of your download, and enable the extension by
editing the php.ini file.)
httpd.conf file in
C:\Program Files\Apache Group\Apache\conf:
LoadModule directives (all commented out) and append at end
LoadModule php4_module "C:/PHP/php4apache.dll"
AddModule directives and append at end:
AddModule mod_php4.c
AddType directives (there should be one there
for application/x-tar) and add
AddType application/x-httpd-php .php
<? phpinfo() ?>
<?
header ("Content-type: image/png");
$im = ImageCreate (250, 100);
$white = ImageColorAllocate ($im, 255, 255, 255);
$text_color = ImageColorAllocate ($im, 233, 0 , 233);
// Five built in fonts 1..5
// (Arguments: image, font-id, x, y, text, color);
ImageString ($im, 1, 5, 5, "Hello world", $text_color);
ImageString ($im, 2, 5, 25, "Hello world", $text_color);
ImageString ($im, 3, 5, 45, "Hello world", $text_color);
ImageString ($im, 4, 5, 65, "Hello world", $text_color);
ImageString ($im, 5, 5, 85, "Hello world", $text_color);
ImagePng ($im);
?>
Accessing this through your browser should result in a simple
graphic page. (PHP-GD has five built in fonts; as noted
in the text, you can use other text display functions that
work with TrueType fonts. You should find many TrueType
font files on your Windows system.)Read and follow the instructions that come with the download, or any of the web sites noted above, to complete a proper installation.
Your PHP download should include the available extensions in its "extensions" folder.
It you need anything, e.g. a different database connection, then simply copy
the necessary
module to your extensions_dir directory and edit your php.ini file.
Along with the downloads, and documentation, the main PHP.net site has current news about PHP. Topics include surveys of usage, and details of various PHP courses and conferences that are to be offered world wide. Other moves to commercialize PHP are reported at the Zend site.
The on line code and tutorial resources for PHP are not yet as comprehensive as those of Perl but there is a growing body of material available. Naturally, there are PHP sections at both Yahoo and Google.
News articles, commentary, tutorials, example code, and components (e.g. shopping carts etc) are available at a number of sites including:
Amazon has something like 90 PHP related books including many that focus on specific issues such as use of PHP and MySQL. There is even a PHP-5 title listed (though not yet available).
A few of the examples from the text are available.