Building the environment

The Unix way - multiple tools working as one

The build process

Order is important because of dependancies. Apache needs to know about PHP, PHP needs to know about MySQL etc.

For our examples, we will build in the following order:

  1. MySQL
  2. Sablotron
  3. PHP
  4. Apache
All of this packages use automake/autoconf, so the "configure; make; make install" process should be familiar. We're assuming you are building from source, and the tarballs have already been untarred.

Building MySQL

Everyone will have a different opinion as to where software should be installed, so most likely the only thing you'll need to do is specify this when you run configure.
./configure --prefix=/opt/mysql
make
make install

Building Sablotron

Sablotron won't require any special configure options, as we'll want to place the libraries in a standard directory (/usr/lib or /usr/local/lib) so the system can make use of them.
./configure
make
make install

Building PHP

Here's where we (might!) run into a circular dependancy; Depending on how you build PHP, Apache needs to know about it in advance. Depending on how you build PHP, PHP needs to know about Apache in advance. To get around this, configure Apache first by changing to the Apache source directory and running configure without any options. Once configure has run it's course, return to the PHP source directory to build PHP.

PHP may be installed in several different ways:

Since we're using Apache for our demonstration, we're going to compile it as an Apache module.

./configure --prefix=/opt/php --with-apache=../path_to_apache_source --with-mysql=/opt/mysql \ 
--with-sablot=../path_to_sablot_source --with-config-file-path=/opt/php
make
make install
"--prefix" obviously sets where PHP will be installed.

"--with-apache" sets where the Apache source lives. PHP will place files in the src/modules/ directory so Apache might activate them when it is built.

"--with-mysql" is used to locate MySQL libraries and header files.

"--with-sablot" is used to locate Sablot sources.

By, PHP will use a configuation file (php.ini) placed in /usr/local/lib. By using the "--with-config-file-path" option we can place it elsewhere (like /etc/php.ini for instance).

Building Apache

Before we run configure, we have to fix a tiny problem.

While we could have easily left out Sablot, it provides us with a good example of what can happen when building multiple tools that have co-dependancies.

PHP will be linked against the Sablot/Expat libraries, as we told it all about them on the configure line for PHP. Since we're building PHP as an Apache module, Apache will need to know where to find them or it won't build. The normal "configure/make/make install" process would fail because Apache doesn't know anything Sablot/expat.

In the Apache source directory, cd into src and edit Configuration.tmpl. Look for the section:

EXTRA_CFLAGS=
EXTRA_LDFLAGS=
EXTRA_LIBS=
EXTRA_INCLUDES=
EXTRA_DEPS=
Here is where we will tell Apache about Sablot/Expat:
EXTRA_CFLAGS=
EXTRA_LDFLAGS= -L/usr/lib
EXTRA_LIBS= -lexpat
EXTRA_INCLUDES= -I/usr/include -I/usr/local/include
EXTRA_DEPS=
And now we're ready to build Apache:
./configure --prefix=/opt/apache --activate-module=src/modules/php4/libphp4.a
make
make install
You should edit /opt/apache/conf/httpd.conf and make sure it's correctly configured; note that you should also check for the line:
AddType application/x-httpd-php .php
Whew! That's it... everything should be installed now. You should be able to start up apache with:
/opt/apache/bin/apachectl start

Summary of build process

cd /usr/local/src/mysql
./configure --prefix=/opt/mysql
make
make install

cd /usr/local/src/Sablot
./configure
make
make install

cd /usr/local/src/apache
./configure

cd /usr/local/src/php
./configure --prefix=/opt/php --with-apache=../path_to_apache_source --with-mysql=/opt/mysql \ 
--with-sablot=../path_to_sablot_source --with-config-file-path=/opt/php
make
make install

cd /usr/local/src/apache/src
vi Configuration.tmpl (make changes)
cd ..
./configure --prefix=/opt/apache --activate-module=src/modules/php4/libphp4.a
make
make install