[jjones at darkside.dynup.net: PHP4 hint]

J. Jones jjones at darkside.dynup.net
Mon Jul 9 19:10:33 PDT 2001

I forgot to CC: you guys.. this is just FYI.. don't commit :)

----- Forwarded message from "J. Jones" <jjones at darkside.dynup.net> -----

From: "J. Jones" <jjones at darkside.dynup.net>
Subject: PHP4 hint
Date: Mon, 9 Jul 2001 21:03:19 -0500
To: lfs-apps at linuxfromscratch.org
Message-ID: <20010709210319.D6940 at darkside.dynup.net>
User-Agent: Mutt/1.3.19i
X-Mailer: Linux darkside 2.4.6
Reply-To: lfs-apps at linuxfromscratch.org

Ok guys.. this was formerly the apache+php4+sql hint.. it is hereby
rendered obsolete.

This hint is solely (well, almost) dedicated to PHP.  It relies on Jesse's
up-coming apache hint (*wink*) for that stuff.  Please help me proofread
it.. and offer any suggestions for improvement you may find.  I know it's
rather nuts with all the features, but realize they're all optional.

I have rewritten the imap patch and attached it here.  Please use it (if
you actually follow this hint) instead of the one pointed to by the hint
itself.  Don't consider the imap patch URL valid until this hint gets


To the hint maintainers:
	Please don't commit this yet.. I want to wait for Jesse, so we can
	sync at the same time.

TITLE:		PHP4 hint
AUTHOR:		J. Jones <jjones(at)darkside(dot)dynup(dot)net>

	This hint is strictly dedicated to PHP4 and most of its goodies.  It will
rely heavily on the Apache hints (particularly Jesse's) if you intend to use
php with it (it's great all by itself!).


I have to assume alot of configuration options in this hint,
so if you do stray (mainly on the paths), pay attention! :)

Software used/mentioned/etc in this hint

I have (somewhat) ordered these by dependencies.  Follow the tabs! ;)

	PHP:  http://www.php.net/downloads.php

	MySQL:  http://www.mysql.com/downloads/
		Seemingly the most popular free SQL server.

	PostGreSQL:  http://postgresql.readysetnet.com/sites.html
		Excellent free SQL server.

	Berkeley DB3:  http://www.sleepycat.com/download.html
		Screw SQL, use this!

	zlib:  ftp://ftp.freesoftware.com/pub/infozip/zlib/
		Compression library.

	GD:  http://www.boutell.com/gd/
		1.8.4 is the 'stable' version at this time, although PHP WILL work
		fine with the 2.0.* tree.
		Image creation on the fly.

		libjpeg:  ftp://ftp.uu.net/graphics/jpeg/
			Jpeg library.

		libpng:  ftp://ftp.libpng.org/pub/png/src/
			PNG library.

		libungif:  ftp://prtr-13.ucsc.edu/pub/libungif/
			Patent-free gif library.

		libttf/libfreetype:  http://freetype.sourceforge.net/
			True Type font library (YOU WANT THIS!).

	OpenSSL:  http://www.openssl.org/
		Wonderful encryption library.

	mhash:  http://mhash.sourceforge.net/dl
		Provides access to several hashing algorithms.

	(lib)mcrypt:  http://mcrypt.hellug.gr/
		Provides access to several encryption schemes.

	readline:  ftp://ftp.gnu.org/gnu/readline/
		GNU readline (It's what makes bash so cool).

	pspell:  http://pspell.sourceforge.net/
		The new API for aspell/ispell.

	Imap:  ftp://ftp.cac.washington.edu/imap/old/imap-2000c.tar.Z
		WU's imap library.
		2000c please, not the latest beta they'd like you to have :)

	Curl:  http://curl.haxx.se/download.html
		Client URL library (it's great!).

	libxml:  http://www.xmlsoft.org/#Downloads
		XML DOM library, not to be confused with apache's expat,
		used by php's xml parser.

	LDAP:  http://www.openldap.org/software/download/
		LDAP server and library.

Building the packages

Most of the above packages are a fairly straight-forward build.  I have
documented only the ones that may pose a problem.

Some of them are documented in other LFS hints.  For all of the image libraries
and zlib, see the X11 hint.  For Berzerkeley DB, see the sendmail hint for
proper installation.

If you plan on using MySQL's DB3 support (it's how it gets transaction support),
MySQL's hacked version of this library will/should work just fine.

	Instructions for 1.8.4

	Extract the gd-1.8.4 source.  Download the patch from
	Applying this patch should be as simple as:
		zcat gd--shared.diff.gz | patch -p0

	Edit the Makefile as you see fit (installation prefixes, possible removal of
	the freetype flags, which I don't recommend at all).  The Makefile will
	read the $CFLAGS environment variable, so don't worry about those.

	make all install

	Instructions for 2.0.1

	It appears to be as simple as issuing a make and following the directions
	printed.  ;)

	It will build a shared library by default, which was the sole purpose of
	the patch against 1.8.4.

	The newest imap c-client libs are very beta.  I recommend sticking with the
	latest stable release, 2000c.  My patch won't work on anything else without
	some hacking, anyway. ;)

	Extract the imap-2000c package, download the patch from
	Apply it with:

		zcat imap-2000c-shared.diff.gz | patch -p0

	Cd into the imap-2000c directory, and issue the following commands:

		chmod a+x Build-me

	That should be all there is to it.  This source tree is rather nasty in my
	opinion, so if the build fails for you, yell at me.  Email me the WU-imap.sucks
	file created by:

		make clean
		./Build-me >WU-imap.sucks 2>&1

	and I'll see what I can do.


	These instructions are based on 4.0.6.  PHP has a great team of very active
	developers.. many features can be added (and removed) between releases.
	These are only guaranteed to work on 4.0.6.

	Basically, we will strip the php interpreter down to the bare minimum then
	build php's extras as shared objects which can be loaded by scripts
	(or at startup in the php.ini).

	If you'd rather these extra's be in the actual php binaries, you've got
	some work to do.  ;)  I don't believe in any other method(s) other than the
	one's documented here.  Basically, you'll need to remove the "shared," part
	from the --with-feature=shared,/path, and, of course, add that option to
	the ./configure line of which ever ISAPI you're building (apache, cgi,


	PHP Apache module

	The instructions for BOTH a static and a shared apache module are mixed
	together here.  Please note that for the latter, apache must be up and

	Extract the php source.  Enter the directory.  Issue the following, note that
	you must change these paths toooooo:

		./configure \
		--prefix=/path/to/apache \
		--with-config-file-path=/etc/httpd \

	For a static mod_php4 (in the httpd binary (fastest))
		--with-apache=/path/to/apache \

	For a shared mod_php4 (DSO, dynamically loaded by httpd)

	If you would like mysql support built-in to the httpd binary (will make it
	larger), change the following line to --with-mysql=/path/to/mysql

		--without-mysql \
		--disable-xml \
		--without-pear \
		--without-pcre-regex \
		--disable-posix \
		--with-openssl=/path/to/openssl \
		--enable-trans-sid \
		make all install

		Most of the above options are just removing features that would
		otherwise increase the size of the apache module.
		--enable-trans-sid enables PHP's transparent session id propagation
		support (it will rewrite HTML tags to keep the session id around).
		--with-mm=/usr tells PHP to use the mm library (which you installed
		during the apache hint, right?) with its session support.

	If you chose the shared mod_php4 route, ignore the following.  Else, go back
	to the apache hint.  You need to add the following line to apache's
	./configure line:


	Come back to me when you're finished with the apache hint and we'll load
	php with all it's fancy features.

	PHP CGI interpreter

	This is completely optional, but nice to have, in my opinion.  This will
	create a php binary interpreter, which you can use just like perl or sh,
	and to debug/lint your scripts.  Do NOT use this for web pages.

	In the php source directory, do the following:

		make distclean
		./configure \
		--prefix=/usr/local \
		--with-config-file-path=/usr/local/etc \
		--enable-force-cgi-redirect \
		--enable-discard-path \
		--without-mysql \
		--disable-session \
		--without-pcre-regex \
		--disable-posix \
		--disable-xml \
		make all install

	You will now have a /usr/local/bin/php command line interpreter.

	PHP's extras

	Now the fun part.  Do a make distclean on the php source tree.

		* PHP has a bundled mysql client library, so it doesn't require
		* mysql to be installed to support it.

		* DOM XML (libxml) requires BOTH libxml-1.* and libxml2-* to be
		* installed.

		* WDDX is broken, IMHO.  It depends on php's xml support, which is ok,
		* but it won't build itself outside of the php binary (as a shared
		* module).  If you need it, you will have to add the configure options
		* to the above directions..

	./configure options  

	Database stuff... 

		For MySQL support...
		--with-mysql=shared,/optional/path/to/mysql (see note above)

		For PostGreSQL support...

		--enable-dba=shared  == enable the db abstraction layer
		--with-db3=/usr  == add db3 support to it!

		For dbx support (this looks interesting.. sorta like a generic sql
		api (about time, eh))

		For old-school dbase support (hey, it's builtin, why not?)	

		Ditto, but filepro
		--enable-filepro=shared  == bundled filepro support (builtin)

	For GD support...

		If you installed gd 1.8.4, add these two

	Encryption and compression stuff...
		For mhash...
		For mcrypt...
		For zlib...
		For bzip2...

	Imap support...

	XML stuff...
		--with-xml=shared == XML parsing support (builtin)
		--with-dom=shared,/path/to/libxml  == DOM XML stuff
		--enable-wddx=shared  == XML wddx stuff (builtin)

	Network-ish stuff...
		--with-curl=shared,/path/to/curl == use curl!
		--enable-ftp=shared  == enable ftp functions (builtin)
		--enable-sockets=shared == enable network socket functions {builtin)
		--enable-yp=shared == yp support (builtin)
		--with-ldap=shared,/path/to/openldap == enable ldap functions

	Misc unix-specific stuff...
		--with-gettext=shared,/usr == GNU gettext support!
		--with-readline=shared,/usr == GNU Readline support!
		--with-pspell=shared,/path/to/pspell == Pspell support
		--enable-bcmath=shared == bcmath precision calculations (builtin)
		--with-gmp=shared == GNU precision math lib
		--enable-ctype=shared == character type functions (builtin)
		--enable-shmop=shared == shmop support (builtin)
		--enable-sysvsem=shared == SystemV semaphore functions (builtin)
		--enable-sysvshm=shared == SystemV shared memory functions (builtin)

		--with-pcre-regex=shared  == Perl Compatible Regular Expressions! (builtin)
		--enable-posix=shared  == posix functions (builtin)
		--enable-calendar=shared == calendar conversion (builtin)

	The =shared options creates a shared library which php will load,
	allowing you to update one or more modules/features, without recompiling
	apache and php.

	Here's the entire ./configure command, with every option shown above.  Be sure
	to fix the paths.  ;)

	CFLAGS="$CFLAGS -L/usr/X11R6/lib -I/usr/X11R6/include \
	-L/usr/local/lib -I/usr/local/include" \
	./configure \
		--with-mysql=shared,/opt/MySQL \
		--with-pgsql=shared,/opt/PostGreSQL \
		--enable-dba=shared \ 
		--with-db3=/usr \
		--enable-dbx=shared \
		--enable-dbase=shared \
		--enable-filepro=shared \
		--with-gd=shared,/usr/X11R6 \
		--with-jpeg-dir=/usr \
		--with-png-dir=/usr \
		--with-zlib-dir=/usr \
		--with-xpm-dir=/usr/X11R6 \
		--with-freetype-dir=/usr/X11R6 \
		--enable-gd-imgstrttf \
		--enable-gd-native-ttf \
		--with-ttf=/usr/X11R6 \
		--with-t1lib=/usr/X11R6 \
		--with-mhash=shared,/usr/local \
		--with-mcrypt=shared,/usr/local \
		--with-zlib=shared,/usr \
		--with-bz2=shared,/usr \
		--with-imap=shared,/usr/local \
		--with-imap-ssl=/usr \
		--with-xml=shared \
		--with-dom=shared,/usr/X11R6 \
		--enable-wddx=shared \
		--with-curl=shared,/usr/local \
		--enable-ftp=shared \
		--enable-sockets=shared \
		--enable-yp=shared \
		--with-ldap=shared,/opt/LDAP \
		--with-gettext=shared,/usr \
		--with-readline=shared,/usr \
		--with-pspell=shared,/usr/local \
		--enable-bcmath=shared \
		--with-gmp=shared \
		--enable-ctype=shared \
		--enable-shmop=shared \
		--enable-sysvsem=shared \
		--enable-sysvshm=shared \
		--with-pcre-regex=shared \
		--enable-posix=shared \
		--enable-calendar=shared \
		| tee ~/php-config.log

	This script tends to fly by fairly quick.. so check the ~/php-config.log for
	the results.

	Once everything looks ok, issue a make.  Once completed, choose a location to
	keep these .so's, like /usr/local/lib/php, cd into the modules directory, and
	cp *.so /usr/local/lib/php/.  You may wish to strip --strip-unneeded those
	modules also.

	Now, the key here is your php.ini.  Copy the php.ini-dist file from the php
	source directory to /etc/httpd/php.ini.  In this file, change the extension_dir
	to the /path/you/copied/the/*.so's.

	If you wish for php to load any of these at startup, add extension=name.so to
	the php.ini.  To load these at runtime, this seems the most effective way.

	Say I need the mysql support.  At the beginning of my script, I'd have this:

		if ( ! function_defined ('mysql_query')) {
			if ( ! dl('mysql.so')) {
				print ("Error:  No MySQL support found!\n");
				exit (1);

	You may wish to ldd all of these .so's.. they will kill the httpd children if
	they are dl()'d and can't find a library they need (it's better than killing
	apache altogether though, eh?).

Common problems?

	What? Problems with PHP, apache, and friends? Unheard of!

End of hint

----- End forwarded message -----

More information about the hints mailing list