PHP DevCenter

oreilly.comSafari Books Online.Conferences.

We've expanded our LAMP news coverage and improved our search! Search for all things LAMP across O'Reilly!

Search
Search Tips

advertisement

Listen Print Subscribe to PHP Subscribe to Newsletters
PHP Admin Basics

Installing PHP as an Apache DSO

03/15/2001

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 http://www.php.net/FAQ.php#6.11 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_CFLAGS_SHLIB = ' ';
my $CFG_LD_SHLIB = ' ';
my $CFG_LDFLAGS_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_CFLAGS_SHLIB = '-fpic -DSHARED_MODULE';
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/libphp4.so 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.




Tagged Articles

Be the first to post this article to del.icio.us

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com