GuidesPHP on Apache: The Definitive Installation Guide Page 4

PHP on Apache: The Definitive Installation Guide Page 4

ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.




Static modules are linked into the Apache server itself, and cannot be
removed without recompiling. This means that they can consume resources, such
as memory, even if not used or activated. It also means rebuilding the entire
server any time a single module is altered (such as upgrading the PHP
installation). The Apache Group now strongly encourages the use of DSOs
(dynamic shared objects) in preference to static modules because of their
flexibility. While static modules are far from deprecated, I’m including the
steps here only for completeness; Linux has no problem with dynamic
modules—use the dynamic-module method instead of the static.

In order to build mod_php for static inclusion in the Apache
server it’s necessary to jump back and forth between the Apache and PHP
directories, following a series of interdependent configuration and compilation
steps. You indicate that you’re building mod_php statically by
using the --with-apache switch on the
./php/php3/configure script invocation.

    % #
    % # Preconfigure Apache so that PHP knows where things are
    % #
    % cd ./apache-1.3
    % ./configure --prefix=/usr/local/web/apache
    % #
    % # Now configure and build PHP as a module
    % #
    % cd ../php/php3
    % rm -f config.status config.cache
    % ./configure --with-apache=../../apache-1.3 other-switches
    % make
    % make install
    % #
    % # Now *really* configure Apache, and build it
    % #
    % cd ../../apache-1.3
    % ./configure --prefix=/usr/local/web/apache 
    > --activate-module=src/modules/php3/libphp3.a
    % make
    % #
    % # Install the resulting httpd application
    % #
    % /usr/local/web/apache/bin/apachectl stop
    % cp src/httpd /usr/local/web/apache/bin
    % cd ../php/php3
    % cp php3.ini-dist /usr/local/lib/php3.ini
    % /usr/local/web/apache/bin/apachectl start

(You will probably have to execute the last five commands as
root.)

See how complicated this is? Repeat for every PHP module rebuild.

Building mod_php as a Dynamically Loaded Object

To build PHP as a dynamic Apache module, build and install the Apache server
itself using the APACI method (i.e., with the
./apache-1.3/configure script). This is because the PHP
configure script needs to use one of the files that APACI
installs.

To build PHP as a dynamic shared object (DSO), use the following sequence of
commands:

    % cd ./php/php3/
    % rm -f config.status config.cache
    % make clean
    % ./configure --with-apxs=/usr/local/web/apache/bin/apxs other-options
    % make
    % /usr/local/web/apache/bin/apachectl stop   # shut down Apache entirely
    % make install
    % /usr/local/web/apache/bin/apachectl start  # restart Apache

When that's all done, your Apache server should be capable of handling PHP
CGI scripts and PHP-enabled Web pages. And to upgrade just PHP from a new
version, just repeat the process--without touching any other part of Apache.

For building PHP on Red Hat Linux 6.1 and using the Apache RPMs, fix
a broken file provided by them before executing the above commands. See the
"Fixing Red Hat 6.1's apxs Script" appendix in this article for the
details.

Testing Your Installation

If you built PHP as a script interpreter, verify that it is working
correctly by creating and executing a test script such as the following:

Get the Free Newsletter!

Subscribe to Daily Tech Insider for top news, trends & analysis

Latest Posts

Related Stories