Appendix I. Compiling PHP

Table of Contents

I.1. Compiling PHP4
I.1.1. Client version
I.1.2. Apache module
I.1.3. CGI extension
I.2. Compiling PHP5
I.2.1. Client version
I.2.2. Apache module
I.2.3. CGI extension

Usually the included PHP version is adequate but if problems persists it is a good idea to be able to compile PHP yourself. This way you will also be able to more quickly upgrade to newer version of PHP which might have fix for a particular nasty bug that may have crept in.

In the following sections we give examples of Unix shell scripts that will show typical compile configuration for a downloaded PHP distribution. These compile configuration scripts will make both the GD and FreeType libraries included in the executable.

In order to compile your downloaded PHP distribution first copy and save these scripts to a local file and make that file runnable. Then run one of the selected configurations below and do a normal "make".

Tip

When running make you can speed up the compilation by telling make to use a number of parallel compile processes. Since most modern system have at least two cores a typical invocation of make would be to make use of three parallel compile time processes. This is done by using the -j argument. For example as

make -j3

It is possible to compile PHP into (at least) three variants

  1. as a command line tool

  2. as a Apache extension module (this is probably the most common variant)

  3. as a CGI module to be used by a HTTP server (this is slower than running PHP as a module since it needs to be read from disk and the process created every time a PHP script needs to be executed.)

There is one crucial difference of importance when using PHP to generate images. Both the CGI module and the client variant are both standalone executables so what is the difference? The crucial difference is that the CGI module will by default output a MIME header before it outputs data while the client version will not.

The following sections have one compile script for each of the three major versions.

Caution

You should make sure that the proposed directory paths in the scripts match your particular server setup as this can vary from system to system.

I.1. Compiling PHP4

I.1.1. Client version

#! /bin/sh
./configure --prefix=/usr/share --datadir=/usr/share/php \
--libdir=/usr/share/php --includedir=/usr/include \
--bindir=/usr/bin \
--with-config-file-path=/etc/php4/cli \
--with-config-file-scan-dir=/etc/php4/cli \
--enable-mbstring --enable-mbregex \
--with-mysql  \
--with-gd --enable-gd-imgstrttf --enable-gd-native-ttf \
--with-zlib-dir=/usr/lib \
--with-png-dir=/usr/lib --with-jpeg-dir=/usr/lib --with-xpm-dir=/usr/X11R6 \
--with-tiff-dir=/usr/lib --with-ttf-dir=/usr/lib \
--with-freetype-dir=/usr/lib \
--enable-ftp \
--enable-memory-limit \
--enable-bcmath -enable-calendar \
--enable-ctype --with-ftp \
--enable-magic-quotes \
--enable-inline-optimization \
--with-bz2 \
--with-iconv

I.1.2. Apache module

#! /bin/sh
./configure --prefix=/usr/share --datadir=/usr/share/php --with-apxs2=/usr/sbin/apxs2 \
--libdir=/usr/share --includedir=/usr/include \
--bindir=/usr/bin \
--with-config-file-path=/etc/php4/apache2 \
--enable-mbstring --enable-mbregex \
--with-mysql  \
--with-gd --enable-gd-imgstrttf --enable-gd-native-ttf \
--with-zlib-dir=/usr/lib \
--with-png-dir=/usr/lib --with-jpeg-dir=/usr/lib --with-xpm-dir=/usr/X11R6 \
--with-tiff-dir=/usr/lib --with-ttf-dir=/usr/lib \
--with-freetype-dir=/usr/lib \
--enable-ftp \
--enable-memory-limit \
--bindir=/usr/bin \
--enable-bcmath \
--enable-calendar \
--enable-ctype \
--with-ftp \
--enable-magic-quotes \
--enable-inline-optimization \
--with-bz2 \
--with-iconv

I.1.3. CGI extension

#! /bin/sh
./configure --prefix=/usr/share --datadir=/usr/share/php \
--libdir=/usr/share --includedir=/usr/include \
--bindir=/usr/bin \
--with-config-file-path=/etc/php4/apache2 \
--with-config-file-scan=/etc/php4/apache2 \
--enable-mbstring --enable-mbregex \
--with-mysql  \
--with-gd --enable-gd-imgstrttf --enable-gd-native-ttf \
--with-zlib-dir=/usr/lib \
--with-png-dir=/usr/lib --with-jpeg-dir=/usr/lib --with-xpm-dir=/usr/X11R6 \
--with-tiff-dir=/usr/lib --with-ttf-dir=/usr/lib \
--with-freetype-dir=/usr/lib \
--enable-ftp \
--enable-memory-limit \
--bindir=/usr/bin \
--enable-bcmath \
--enable-calendar \
--enable-ctype \
--with-ftp \
--enable-magic-quotes \
--enable-inline-optimization \
--with-bz2 \
--with-iconv