0

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.

kentr
  • 181
  • 1
  • 1
  • 9

2 Answers2

5

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.
kentr
  • 181
  • 1
  • 1
  • 9
1

First things first: if you're talking about a production system and you're not the sysadmin (your comment indicates you aren't), don't touch the system.

If you elect to ignore that advice and inadvertently break things your sysadmin will probably cause you serious bodily harm upon his return (and will be entirely justified in doing so -- Nothing is worse than coming back from vacation to find someone has broken things by trying to "help", except maybe getting an emergency call while you're on vacation).


All that said, if you want to do this manually you must determine exactly what is being installed by the php5-pgsql package (in addition to PHP compiled with Postgres support it also includes the pgsql PDO extension, and possibly other stuff). Then you need to manually install all of the pieces.

There is no guarantee that you will be able to assemble this puzzle: For example, PECL (where you'd get the PDO extension) is only tested on supported versions of PHP. It will probably work, but if it doesn't the solution is "Upgrade PHP to a supported release".


To echo what other people have said in their comments:

Locking your system to a specific version of PHP is Bad.
If you have a system that requires PHP 5.2 (long since unsupported, and riddled with known security holes) it's time to sit down with your sysadmin and write a memo to the 2 levels of management above you. (If your sysadmin doesn't see why this is a problem you write the memo and CC him.)

Locking your system to a specific patch level of PHP is Insane.
If you have a system that absolutely requires PHP 5.2.4 you should have already written a memo about it, and screamed at everyone in person about how it's unsustainable and will create major problems in the future.
If you had written that memo this is where you get to look prescient and say "Remember that memo?" -- Otherwise you get to write it now (which doesn't look as good, but at least shows you're doing your job and pointing out serious risks to the business).

voretaq7
  • 79,879
  • 17
  • 130
  • 214
  • I have plenty of leeway to touch the system and install software, thanks much. I was interim sysadmin before he arrived, and still manage to keep my right to sudo privs. Don't need a lecture on locking PHP. We have it locked for a reason. As stated, just needed the extension so that we can launch a project. – kentr Sep 17 '13 at 17:58
  • 2
    @kentr You tell us none of this in your question and you give us a comment saying "When my sysadmin returns from vacation" -- frankly that merits a lecture in my book. If you are confident you are both capable and *authorized* to do what you're proposing in *your specific environment* that's great, but I stand by every word in my answer for the general case :-) – voretaq7 Sep 17 '13 at 18:04
  • Your words have merit. I wouldn't even be able to do this w/o sudo privileves :-). – kentr Sep 17 '13 at 18:59