Java LAMP How-To Part 3
Build and Install Apache (with DSO support)
 
The advantage to building Apache with support for dynamically loaded modules is that in the future, you can add functionality to your webserver by just compiling and installing modules, and restarting the webserver. If the features were compiled into Apache, you would need to rebuild Apache from scratch every time you wanted to add or update a module (like PHP for example). Your Apache binary is also smaller, which means more efficient memory usage. The downside to dynamic modules is a slight performance hit compared to having the modules compiled in.
 
TECHSNIP: Here are the configure options.........
 
[root@localhost httpd-2.0.59]# ./configure --help
`configure' configures this package to adapt to many kinds of systems.
 
Usage: ./configure [OPTION]... [VAR=VALUE]...
 
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
 
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print `checking...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for `--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or `..']
 
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local/apache2]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
 
By default, `make install' will install all the files in
`/usr/local/apache2/bin', `/usr/local/apache2/lib' etc. You can specify
an installation prefix other than `/usr/local/apache2' using `--prefix',
for instance `--prefix=$HOME'.
 
For better control, use the options below.
 
Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--datadir=DIR read-only architecture-independent data [PREFIX/share]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--infodir=DIR info documentation [PREFIX/info]
--mandir=DIR man documentation [PREFIX/man]
 
System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD]
--target=TARGET configure for building compilers for TARGET [HOST]
 
Optional Features:
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--enable-layout=LAYOUT
--enable-v4-mapped Allow IPv6 sockets to handle IPv4 connections
--enable-exception-hook Enable fatal exception hook
--enable-maintainer-mode
Turn on debugging and compile time warnings
--enable-modules=MODULE-LIST
Modules to enable
--enable-mods-shared=MODULE-LIST
Shared modules to enable
--disable-access host-based access control
--disable-auth user-based access control
--enable-auth-anon anonymous user access
--enable-auth-dbm DBM-based access databases
--enable-auth-digest RFC2617 Digest authentication
--enable-isapi isapi extension support
--enable-file-cache File cache
--enable-echo ECHO server
--disable-charset-lite character set translation
--enable-charset-lite character set translation
--enable-cache dynamic file caching
--enable-disk-cache disk caching module
--enable-mem-cache memory caching module
--enable-example example and demo module
--enable-case-filter example uppercase conversion filter
--enable-case-filter-in example uppercase conversion input filter
--enable-dumpio I/O dump filter
--enable-ldap LDAP caching and connection pooling services
--enable-auth-ldap LDAP based authentication
--enable-ext-filter external filter module
--disable-include Server Side Includes
--enable-deflate Deflate transfer encoding support
--disable-log-config logging configuration
--enable-log-forensic forensic logging
--enable-logio input and output logging
--disable-env clearing/setting of ENV vars
--enable-mime-magic automagically determining MIME type
--enable-cern-meta CERN-type meta files
--enable-expires Expires header control
--enable-headers HTTP header control
--enable-usertrack user-session tracking
--enable-unique-id per-request unique ids
--disable-setenvif basing ENV vars on headers
--enable-version determining httpd version in config files
--enable-proxy Apache proxy module
--enable-proxy-connect Apache proxy CONNECT module
--enable-proxy-ftp Apache proxy FTP module
--enable-proxy-http Apache proxy HTTP module
--enable-ssl SSL/TLS support (mod_ssl)
--enable-optional-hook-export
example optional hook exporter
--enable-optional-hook-import
example optional hook importer
--enable-optional-fn-import
example optional function importer
--enable-optional-fn-export
example optional function exporter
--enable-bucketeer buckets manipulation filter
--enable-static-support Build a statically linked version the support
binaries
--enable-static-htpasswd
Build a statically linked version of htpasswd
--enable-static-htdigest
Build a statically linked version of htdigest
--enable-static-rotatelogs
Build a statically linked version of rotatelogs
--enable-static-logresolve
Build a statically linked version of logresolve
--enable-static-htdbm Build a statically linked version of htdbm
--enable-static-ab Build a statically linked version of ab
--enable-static-checkgid
Build a statically linked version of checkgid
--enable-http HTTP protocol handling
--disable-mime mapping of file-extension to MIME
--enable-dav WebDAV protocol handling
--disable-status process/thread monitoring
--disable-autoindex directory listing
--disable-asis as-is filetypes
--enable-info server information
--enable-suexec set uid and gid for spawned processes
--disable-cgid CGI scripts
--enable-cgi CGI scripts
--disable-cgi CGI scripts
--enable-cgid CGI scripts
--enable-dav-fs DAV provider for the filesystem
--enable-vhost-alias mass virtual hosting module
--disable-negotiation content negotiation
--disable-dir directory request handling
--disable-imap server-side imagemaps
--disable-actions Action triggering on requests
--enable-speling correct common URL misspellings
--disable-userdir mapping of requests to user-specific directories
--disable-alias mapping of requests to different filesystem parts
--enable-rewrite rule based URL manipulation
--enable-so DSO capability
 
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-apr=DIR|FILE prefix for installed APR, path to APR build tree,
or the full path to apr-config
--with-apr-util=DIR prefix for installed APU, or path to APU build tree
--with-port=PORT Port on which to listen (default is 80)
--with-z=DIR use a specific zlib library
--with-ssl=DIR SSL/TLS toolkit (OpenSSL)
--with-mpm=MPM Choose the process model for Apache to use.
MPM={beos|worker|prefork|mpmt_os2|perchild|leader|threadpool}
--with-module=module-type:module-file
Enable module-file in the modules/<module-type>
directory.
--with-program-name alternate executable name
--with-suexec-bin Path to suexec binary
--with-suexec-caller User allowed to call SuExec
--with-suexec-userdir User subdirectory
--with-suexec-docroot SuExec root directory
--with-suexec-uidmin Minimal allowed UID
--with-suexec-gidmin Minimal allowed GID
--with-suexec-logfile Set the logfile
--with-suexec-safepath Set the safepath
--with-suexec-umask umask for suexec'd process
 
Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
CPPFLAGS C/C++ preprocessor flags, e.g. -I<include dir> if you have
headers in a nonstandard directory <include dir>
CPP C preprocessor
 
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
 
[root@localhost httpd-2.0.59]#
 
Whew! ok maybe we did not need all that but at least you get some idea for what options are there. Its not a cakewalk.
 
Ok, lets get started. We will change to the source directory we created in Section 1, clean out any potential partial compilations, and install the binaries.
 
cd /usr/local/src/httpd-2.0.59
 
make clean
 
./configure --prefix=/usr/local/apache2 --enable-shared=max --enable-rewrite --enable-so --enable-ldap --enable-cgi --with-maintainer-mode
 
make
 
make install
 
Thats it. Apache is installed on the system. Before we create the scripts to start up Apache automatically, lets do the PHP installation.
 
Build and Install PHP
 
This section has only been tested with PHP v4.x. If you are trying to build PHP 5.x, I do not have experience with this yet, and do not provide free support for you to get it working. Please note that there are many options which can be selected when compiling PHP. Some will have library dependencies, meaning certain software may need to be already installed on your server before you start building PHP. You can use the command...
 
./configure --help | less
 
... once you change into the PHP source directory. This will show you a list of all possible configuration switches. For more information on what these switches are, please check the PHP website documentation. So speaking of that, lets get into the right directory.
 
cd /usr/local/src/php-5.1.4
 
This is the set of compilations options we used. To be sure you are compiling with the correct options, consult the requirements of your applications. Ours needed the following - and this is all on one command line:
 
 
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --prefix=/usr/local/apache2/php --with-zlib --with-gettext --enable-ftp --enable-inline-optimization --enable-magic-quotes --enable-mbstring --enable-mm=shared --enable-safe-mode --enable-track-vars --enable-trans-sid --enable-wddx=shared --enable-xml --with-dom --with-gd --with-regex=system --with-xml --with-zlib-dir=/usr/lib
 
Now lets do the installation...
 
make

make install
 
 

TECHSNIP: Messages from the install process of PHP.....

Wrote PEAR system config file at: /usr/local/apache2/php/etc/pear.conf
You may want to add: /usr/local/apache2/php/lib/php to your php.ini include_path
Installing PDO headers: /usr/local/apache2/php/include/php/ext/pdo/

 
 
Now lets place the php.ini file where it can be found normally...
 
cp php.ini-dist /etc/php.ini
 

 
Edit the Apache Configuration File (httpd.conf)
 
I like to keep all my configuration files together in /etc, so I set up a symbolic link from the actual location to /etc:
 
ln -s /usr/local/apache2/conf/httpd.conf /etc/httpd.conf
 
Now open /etc/httpd.conf in your favorite text editor, and set all the basic Apache options in accordance with the official Apache instructions (beyond the scope of this HOWTO).
 
Also recommended is the article on securing Apache.
 
To ensure your PHP files are properly interpreted, and not just downloaded as text files, remove the # at the beginning of the lines which read:
 
#AddType application/x-httpd-php .php
#AddType application/x-httpd-php-source .phps
 
If the AddType lines above don't exist, manually enter them (without the leading # of course) after the line...
 
AddType application/x-tar .tgz
 
... or anyplace within the <IfModule mod_mime.c> section of httpd.conf.
 
If you wish to use other/additional extensions/filetypes for your PHP scripts instead of just .php, add them to the AddType directive:
 
AddType application/x-httpd-php .php .foo
AddType application/x-httpd-php-source .phps .phtmls
 
Add index.php to the list of valid Directory Index files so that your default page in a directory can be named index.php.
 

<IfModule mod_dir.c>
DirectoryIndex index.php index.htm index.html
</IfModule>

 
You can add anything else you want here too. If you want foobar.baz to be a valid directory index page, just add the .baz filetype to the AddType line, and add foobar.baz to the DirectoryIndex line.
 

 
Start Apache
We want to set Apache up with a normal start/stop script in /etc/rc.d/init.d so it can be auto-started and controlled like other system daemons. Set up a symbolic link for the apachectl utility (installed automatically as part of Apache):
 
ln -s /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/apache
 
Then set up auto-start for runlevel 3 (where the server will go by default):
 
ln -s /etc/rc.d/init.d/apache /etc/rc.d/rc3.d/S90apache2
 
Then start the daemon:
 
/etc/rc.d/init.d/apache start
 
 
You can check that it's running properly by typing the following at the command line...
 
ps -ef
 
... and look for the httpd processes.
 
Ok. That's it! Apache and PHP are installed.