The Linux Page

PHP CLI Segmentation Fault with pgsql

Somehow, whenever I tried PHP CLI, it would crash because of PostgreSQL. (i.e. if I use the database in PHP through Apache, no problem, but the same script run via the command line, and it crashes on exit, no matter what I do with the resource handle.)

I was puzzled and did not really know what to do, but some people have found the solution. Now, what is really surprising is the fact that it has been around for ages and not yet fixed in the system.

The fact is, it does not matter too much as long as there is a work around, but you need to apply it yourself...

The problem is a conflict between curl and pgsql. To fix the problem edit the following two files and fix them as shown below1. The idea is simple, we want to load the pgsql system before the curl package (which by default is loaded firts since 'c' is before 'p'.)

File: /etc/php5/conf.d/pgsql.ini

  # configuration for php PostgreSQL module
#extension=pgsql.so

    As you can see, I comment out the extension loading in the PostgreSQL .ini file.

File: /etc/php5/conf.d/curl.ini

  # configuration for php CURL module
  extension=pgsql.so
  extension=curl.so

    And in the curl.ini file we first load pgsql.so.

Voilà!

Reference: http://geek.joshwaihi.com/content/php-cli-segmentation-fault-pgsql

  • 1. The Apache setup will not be affected. The configuration defined under the conf.d folder is specific to the CLI version