Compiling PHP as an Apache module
 Compile PHP as an Apache module

The first two steps configure Apache so that it recognizes shared modules. If you have a compiled version of Apache already installed on your system, proceed to step 3. Note that Mac OS X comes with a pre-installed Apache web server.

  1. Configure Apache to recognize shared modules.

    Execute the following command (entered all on one line) from the directory where your Apache files were extracted:

    $ cd Apache-source-directory
    $ ./configure --enabled-shared=max --enable-module=most --
    prefix=/Apache-installation-directory

    The following example is for Apache version 2.2.9. You must change apache_2.2.9 to the version of Apache you are using.

    $ cd ~/apache_2.2.9
    $ ./configure --enabled-shared=max --enable-module=most --
    prefix=/usr/local/web/apache
  2. Recompile and install the relevant components:

    $ make
    $ make install

    Now you are ready to compile PHP to operate as an Apache module.

  3. Make sure the environment is set up for SQL Anywhere.

    Depending on which shell you are using, enter the appropriate command from the directory where SQL Anywhere is installed (by default, this is /opt/sqlanywhere12). On Mac OS X, the default directory is /Applications/SQLAnywhere12/System.

    If you are using this shell... ...use this command
    sh, ksh, bash
     . ./bin32/sa_config.sh
    csh, tcsh
    source ./bin32/sa_config.csh
  4. Configure PHP as an Apache module to include the SQL Anywhere PHP extension.

    Execute the following commands:

    $ cd PHP-source-directory
    $ ./configure --with-sqlanywhere --with- apxs=/Apache-installation-directory/bin/apxs

    The following example is for PHP version 5.2.11. You must change php-5.2.11 to the version of PHP you are using.

    $ cd ~/php-5.2.11
    $ ./configure --with-sqlanywhere --with- apxs=/usr/local/web/apache/bin/apxs

    The configure script will try to determine the version and location of your SQL Anywhere installation. In the output from the command, you should see lines similar to the following:

    checking for SQL Anywhere support... yes
    checking     SQL Anywhere install dir... /opt/sqlanywhere12
    checking     SQL Anywhere version... 12
  5. Recompile the relevant components:

    $ make
  6. Check that the libraries are properly linked.

    • Linux users (the following example assumes you are using PHP version 5):

      ldd ./.libs/libphp5.so
    • Mac OS X users:

      Refer to your httpd.conf configuration file to determine where libphp5.so is on your computer. Perform the check with the following command:

      otool -L $LIBPHP5_DIR/libphp5.so

      $LIBPHP5_DIR is the directory where libphp5.so is located, according to your server configuration.

      This command outputs a list of the libraries that libphp5.so uses. Verify that libdblib12.so is in the list.

  7. Install the PHP binaries in Apache's lib directory:

    $ make install
  8. Perform verification. PHP does this automatically. All you need is to make sure that your httpd.conf configuration file is verified so that Apache will recognize .php files as PHP scripts.

    httpd.conf is stored in the conf subdirectory of the Apache directory:

    $ cd Apache-installation-directory/conf

    For example:

    $ cd /usr/local/web/apache/conf

    Make a backup copy of httpd.conf before editing the file (you can replace pico with the text editor of your choice):

    $ cp httpd.conf httpd.conf.backup
    $ pico httpd.conf

    Add or uncomment the following lines in httpd.conf (they are not located together in the file):

    LoadModule php5_module   libexec/libphp5.so
    AddModule mod_php5.c
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    Note

    On Mac OS X, the last two lines should be added or uncommented in httpd_macosxserver.conf.

    The first two lines point Apache to the files that are used for interpreting PHP code, while the other two lines declare file types for files whose extension is .php or .phps so Apache can recognize and deal with them appropriately.

 See also