spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / php / corephp / 1 To page 1To page 2To page 3current pageTo page 5
[previous] [next]

An Introduction to PHP

Data Center Architect
The Computer Merchant, Ltd
US-MA-chelsea

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


Listing 1.1 Configuring Apache

./configure \
--server-uid= nobody \
--enable-module= so

The script will examine your system and prepare a make file for Apache. This builds Apache for using shared libraries, one of which will be PHP. You should follow the configuration step with make install, which will compile Apache and install the binaries in the default location. You may wish to test Apache by starting it with the /usr/local/apache/bin/apachectl script.

Next, configure and compile PHP. Listing 1.2 shows a command for configuring PHP with a few extensions, executed within the PHP source code directory. Follow this with a make install. In most cases, PHP can find the libraries it needs for extensions. In Listing 1.2, I'm specifically using the MySQL libraries I have in /usr/libs rather than the MySQL libraries included in the PHP distribution.

Appendix E lists the compile-time configuration directives. You can also get information by running ./configure --help. Running make will create the PHP library, and make install places the PHP module in Apache's directory of modules. It also installs the latest PEAR classes, a collection of standard PHP code.

Listing 1.2 Configuring PHP

./configure \
--with-apxs=/ usr/local/apache/bin/apxs \
--with-zlib \
--with-bz2 \
--with-openssl \
--with-gd \
--enable-exif \
--with-jpeg-dir=/usr \
--with-freetype-dir \
--with-t1lib \
--enable-gd-native-ttf \
--with-mysql=/usr

To supply additional configuration options, PHP uses a file called php.ini. This file should reside in /usr/local/lib, so copy it from the PHP source directory (Listing 1.3):

Listing 1.3 Copying php.ini

cp php.ini-dist /usr/local/lib/php.ini

You may not need to edit this file. It controls certain aspects of PHP, including support for historic behavior. Chapter 15 discusses configuration deriectives you may use in php.ini. Many of them are in the default file. Some you must add.

The last step is to make sure Apache recognizes PHP scripts. Somewhere in Apache's configration file, httpd.conf, you need an AddType directive that matches scripst ending in .php with application/x-httpd-php. You also need to load the PHP module. If the lines in Listing 1.4 do not appear in httpd.conf, add them.

Listing 1.4 Activating PHP for Apache

LoadModule php5_ module libexec/libphp5.so
AddType application/x-httpd-php .php
AddModule mod_ php5.c

This causes all files with the extension .php to be executed as PHP scripts. You may also wish to insert index. php as a default document. When the Apache server is started, it will process PHP scripts. The documentation for Apache has hints for starting Apache automatically. If you have been running Apache previously, you will need to restart it, not just use a kill –HUP command.

Installation on Apache for Windows

Compiling PHP for Windows is not an ordinary task. Windows users typically use binaries available on the PHP Web site. The same is true for Apache. Both packages include automated installers, which makes installation easy. Installing Apache this way is fine. I prefer to install PHP manually, using the archive, because it allows for better flexibility.

Unzip the PHP archive into a directory. I use C:\ PHP, but you can really put it anywhere. Next, copy the file php. ini-dist into your system root directory, which is probably C:\Windows. Rename it php.ini. When PHP is invoked, it looks first for php.ini in this directory. Although you don't need to, you may wish to edit it to change configuration parameters, including automatically loading extensions. Comments in the file explain the purpose of each configuration directive. Chapter 15 discusses them in detail.

The next step is to make sure the required DLL files are in your path. One way is to copy required files to your system directory, such as C:\Windows\system32. Alternatively, you can click on the system icon in the control panel and add your PHP directory to the system path. Your Web server must be able to find php4ts.dll, which is in the root of the PHP installation directory.

Next, configure Apache to load the PHP module. Edit httpd.conf and add the lines in Listing 1.5. These lines load the module and associate the .php extension with PHP script. The final step is restarting Apache.

Listing 1.5 Activating PHP for Apache on Windows

LoadModule php5_ module c:/php/sapi/php5apache.dll
AddType application/x-httpd-php. php
AddModule mod_ php5.c

home / programming / php / corephp / 1 To page 1To page 2To page 3current pageTo page 5
[previous] [next]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint

Created: March 27, 2003
Revised: Sept 1, 2003

URL: http://webreference.com/programming/php/corephp/1