Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 12.0.0 » SQL Anywhere Server - Programming » PHP support » SQL Anywhere PHP extension » Building the SQL Anywhere PHP extension on Unix and Mac OS X » Compiling Apache and PHP


Compiling PHP as an Apache module

The first two steps in the following instructions 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.

 To compile PHP as an Apache module
  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 --

    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 --
  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/
    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/
    • Mac OS X users:

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

      otool -L $LIBPHP5_DIR/

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

      This command outputs a list of the libraries that uses. Verify that 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/
    AddModule mod_php5.c
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

    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.

For information about testing and using your setup, see Running PHP test scripts in your web pages.