Php – How to build & install pgsql PHP extension manually on Ubuntu

PHPphp5postgresqlubuntu-10.04

I've searched high and low and haven't found anything. Perhaps I don't know what to search for.

Environment is Ubuntu Lucid (10.4) with PHP 5.2.4 & PostgreSQL 9.2.

PHP is "held" at 5.2.4 with dpkg --set-selections. I can only find a 5.2.6 version of php5-pgsql, and when I try to install using dpkg, it complains that PHP is at 5.2.4.

Trial run with aptitude install php5-pgsql tells me that it wants to upgrade to PHP 5.3.

Edit: Upgrading PHP is not currently an option.

I should add: I tried building PHP 5.2.4 from source using --with-pgsql --with-pdo-pgsql. Did not get any extensions as a result. Both libpq and libpq-dev are installed.

Best Answer

This appears to do the trick:

  1. Download & unarchive PHP source.
  2. Ensure libpq5 and libpq-dev are installed.
  3. cd php_x.x.x/ext/pgsql
  4. phpize
  5. ./configure
  6. make
  7. sudo make install
  8. edit php.ini to add extension=pgsql.so and any necessary other pgsql directives.
  9. Restart apache.