Subject: Apache, PHP and Postgresql
To: None <pkgsrc-users@netbsd.org>
From: Luke Maurits <lmaurits@gmail.com>
List: pkgsrc-users
Date: 02/26/2007 18:35:36
Greetings all,

I am attempting to integrate Apache, PHP and Postgresql using pkgsrc.

The following packages are showing up as installed when I run pkg_info:

postgresql82-client-8.2.3 PostgreSQL database client programs
postgresql82-server-8.2.3 PostgreSQL database server programs
apache-1.3.34nb6    Apache HTTP (Web) server
ap13-php5-5.2.1nb1  Apache (apache13) module for PHP5
php-5.2.1           PHP Hypertext Preprocessor version 5
php5-pgsql-5.2.1nb1 PHP extension for PostgreSQL databases

To my knowledge, all of these packages are working correctly - I've used
all of them to do their respective jobs independent of one another (as
independent as possible, anyway - there are some obvious inseparable
relations) without any issues that I have noticed.

I'm fairly new to web programming, so to get used to things I have
written a small .php page which queries a postgresql database and
displays the results, formatted as HTML.  If I run this program from the
command line, i.e. execute "php filename.php", then everything appears
to run smoothly - the expected HTML is printed to the standard output
and it includes exactly those results from the database that I expect.

However, when I try to view the page using a web browser,  no output
produced after the call to "pg_connect" is visible.  If I turn error
reporting on in PHP then the following error message is printed after
that first call:

"Warning: dl() [function.dl]: pgsql: Unable to initialize module Module
compiled with module API=20060613, debug=0, thread-safety=0 PHP compiled
with module API=20050922, debug=0, thread-safety=0 These options need to
match...."

I am quite confused by this.  I would understand perfectly if I was
mixing and matching versions of PHP and the postgresql module, but as
the output from pkg_info above shows, I am not - the version is 5.2.1
for both packages, so shouldn't the APIs be compatible?  I know the
postgresql module package has an nb1 on the end of it, but I thought
this referred to small changes, certainly not changes that break API
compatibility.  The date strings in the error message above show a very
wide gap - on the order of nine months!  I don't see how this is
possible.  Furthermore, the very same program runs fine from the command
line, which suggests that my installed version of PHP is absolutely able
to use my installed postgresql module.  I can't see how this could
change when the PHP interpreter is invoked by Apache instead of my
command line.

If anybody can give me any advice on how to troubleshoot this, I'd be
most appreciative.  Have I done something wrong?  Or is this a problem
with the packages themselves, e.g, an old version of PHP is being
mistakenly distributed as a newer version?  Is anybody else on the list
using an Apache, PHP, Postgresql setup installed from pkgsrc and if so
how did you go about it?

Many thanks,
Luke