PHP DevCenter
oreilly.comSafari Books Online.Conferences.


PHP Admin Basics

Installing PHP as an Apache DSO


Also in PHP Admin Basics:

Common PHP Installation Problems

Securing a PHP Installation

PHP Configuration Directives

The PHP Configuration File

Installing PHP on a Windows System

One useful feature provided by the tight integration of PHP with Apache is the ability to install PHP as a dynamically loadable Apache module. This is a systems administrator's dream because it allows developers to upgrade PHP without having to recompile Apache. If you have ever gone through the 1.5 million steps required to install ApacheSSL, you can appreciate the value in this option.

For more information on what dynamically shared objects (DSOs) are, see Apache's online documentation on the subject. Now let's get started!

To compile PHP as a dynamically loadable module or DSO, you pass the --with-apxs option to the configure script. If you know the location of the Apache apxs file, you can supply that to the switch with --with-apxs=/usr/local/apache/apxs.

It's possible you'll see an error message:

configure: error: Sorry, I cannot run apxs. Either you need to install Perl or you need to pass the absolute path of apxs by using --with-apxs=/absolute/path/to/apxs

If you get this error, chances are you already have Perl installed and you've passed the absolute path of apxs. The problem is that Apache wasn't compiled with mod_so support. Mod_so is compiled with Apache by default unless you specifically tell it not to with a --disable-module=so configuration flag.

After making the decision to re-enable Apache DSO support and trying the PHP configuration again, you'll probably think everything is kosher. Break out the party hats! Except.... you get another error. Take a look at the following example:

dbrogdon@webdev:~/php_source$ ./configure --with-apxs=/usr/local/apache/apxs

WARNING: Your /usr/local/apache/bin/apxs script is most likely broken.

Please go read and make the changes described there and try again.

So, doing what the man page says we find that apxs needs to be educated. The problem is it doesn't have the proper compiler and flag variables. Edit the apxs file and look for the following lines:

my $CFG_LD_SHLIB = ' ';

If the values of these variables are indeed blank (as shown above) then apxs is broken (as demonstrated by your high blood pressure). The lines should look like this:

my $CFG_LD_SHLIB = 'gcc';
my $CFG_LDFLAGS_SHLIB = q(-shared);

Also, Red Hat ships a broken apxs file with their 6.1 and 6.2 versions of Linux. The following line:

my $CFG_LIBEXECDIR = 'modules';

should be changed to:

my $CFG_LIBEXECDIR = '/usr/lib/apache';

Having fixed apxs, you can compile PHP. After compiling PHP with make install as shown:

cd ~/php_source; make install

you'll need to stop and re-start Apache using apachectl:

dbrogdon@webdev:~/php_source$ /usr/local/apache/bin/apachectl stop
dbrogdon@webdev:~/php_source$ /usr/local/apache/bin/apachectl start

Ack! Another error!

API module structure `php4_module' in file /usr/local/apache/libexec/ is garbled - perhaps this is not an Apache module DSO?

Now what?! Chances are you tried compiling PHP without cleaning up your sources in both PHP and Apache. Meaning, when you cleaned up all those ugly errors from previous configures and compiles there were some remnants of those bugs left over. To remedy this, you will need to make sure you do one of the following two commands on PHP and Apache before compiling them. Otherwise they'll contain conflicting headers.

dbrogdon@webdev:~/php_source$ make clean
dbrogdon@webdev:~/php_source$ make distclean

Finally, when compiling Apache, make sure you don't use the --activate-module=src/modules/php4/libphp4.a option, because you are not compiling PHP as a standard Apache module.

Congratulations! You've finished your installation of PHP as an Apache DSO. The next time a new version, sub-version, or patch-level of PHP is released, you'll only need to recompile PHP. So if you've been looking for a reason to order pizza and watch The Matrix for the 22nd time, there's no time like the present! With all the time you'll save using PHP as an Apache DSO, you can afford to take a breather. Enjoy!

Darrell Brogdon is a web developer for SourceForge at VA Linux Systems and has been using PHP since 1996.

Read more PHP Admin Basics columns.

Return to the PHP DevCenter.

Valuable Online Certification Training

Online Certification for Your Career
Earn a Certificate for Professional Development from the University of Illinois Office of Continuing Education upon completion of each online certificate program.

PHP/SQL Programming Certificate — The PHP/SQL Programming Certificate series is comprised of four courses covering beginning to advanced PHP programming, beginning to advanced database programming using the SQL language, database theory, and integrated Web 2.0 programming using PHP and SQL on the Unix/Linux mySQL platform.

Enroll today!

Sponsored by: