Installing PHP with unixODBC

Greek translation courtesy of Dimitris Galatas

This install procedure is based on apache 1.3.12 and PHP 3.0.16, but is identical back at least to apache 1.3.6 and php 3.0.9. The PHP4 from beta 3 will have a configure option to use unixODBC so most of the following will be redundant.

This document assumes that unixODBC has been built and installed, in this case in the default location /usr/local, and that both Apache and PHP have been untarred in the users home directory.

  1. In the Apache directory run the following command
       ./configure --prefix=/www
    
    plus any other local config you need

  2. Create a file in /usr/local/include called odbc.h containing the following three lines
       #include <sql.h>
       #include <sqlext.h>
       #include <odbcinst.h>
    
    replacing /www with your desired apache install path

  3. Move to the PHP directory Define the following environment variables
       CFLAGS="-I/usr/local/include"
       LDFLAGS=
       CUSTOM_ODBC_LIBS="-L/usr/local/lib -lodbc"
    
    remember to export these variables
       export CFLAGS LDFLAGS CUSTOM_ODBC_LIBS 
    

  4. Configure PHP with
       ./configure --with-apache=../apache_1.3.12 --with-custom-odbc=/usr/local  --enable-track-vars
    
    plus any other local config you need then...
       make
       make install
    

  5. Go back to your apache directory, and do
       ./configure --prefix=/www --activate-module=src/modules/php3/libphp3.a
       make
       make install
    

  6. Back to the PHP directory Then to quote from the PHP INSTALL
       cp php3.ini-dist /usr/local/lib/php3.ini
       You can edit /usr/local/lib/php3.ini file to set PHP options.
       Edit your httpd.conf or srm.conf file and add:
         AddType application/x-httpd-php3 .php3
    
    
    
And that should be that.

Apache DSO support

A additional problem has been found if you are building PHP as a dynamic shared object with apache. As by default unixODBC builds with thread support and by default apache does not, if they are not linked together in the build and only meet at run time the combination will fail.

There are two ways around this ether define and export the following environment vars before building apache

export CFLAGS=-D_REENTRANT
export LFLAGS=-lpthread
./configure --prefix=www
or rebuild unixODBC without thread support by configuring ./configure --enable-threads=no

In both cases remember to delete the file config.cache from the root directory of Apache or unixODBC

If this is of any help to someone, good, any problems let me know.

Nick Gorham