Do I have to recompile PHP for adding Postgres PDO support?

Issues related to software problems.
Post Reply
success17
Posts: 5
Joined: 2015/07/03 07:07:50

Do I have to recompile PHP for adding Postgres PDO support?

Post by success17 » 2015/07/03 07:16:50

Hi,

1) I have a dedicated server Centos server
2) want to use Postgres PDO driver from my php code
3) it currently says: Fatal error: Uncaught exception 'PDOException' with message 'could not find driver'
4) I checked phpinfo here is the output for critical bits:

configure command:
./configure' '--disable-fileinfo' '--enable-bcmath' '--enable-calendar' '--enable-exif' '--enable-ftp' '--enable-gd-native-ttf' '--enable-intl' '--enable-libxml' '--enable-mbstring' '--enable-pdo=shared' '--enable-soap' '--enable-sockets' '--enable-sqlite-utf8' '--enable-wddx' '--enable-zip' '--prefix=/usr/local' '--with-bz2' '--with-curl=/opt/curlssl/' '--with-curlwrappers' '--with-freetype-dir=/usr' '--with-gd' '--with-gettext' '--with-icu-dir=/usr' '--with-imap=/opt/php_with_imap_client/' '--with-imap-ssl=/opt/openssl' '--with-jpeg-dir=/usr' '--with-kerberos' '--with-libexpat-dir=/usr' '--with-libxml-dir=/opt/xml2' '--with-libxml-dir=/opt/xml2/' '--with-mcrypt=/opt/libmcrypt/' '--with-mysql=/usr' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-mysqli=/usr/bin/mysql_config' '--with-openssl=/opt/openssl' '--with-openssl-dir=/opt/openssl' '--with-pcre-regex=/opt/pcre' '--with-pdo-mysql=shared' '--with-pdo-sqlite=shared' '--with-png-dir=/usr' '--with-pspell' '--with-tidy=/opt/tidy/' '--with-xmlrpc' '--with-xpm-dir=/usr' '--with-xsl=/opt/xslt/' '--with-zlib' '--with-zlib-dir=/usr'

PDO drivers: sqlite, mysql

5) I tried yum install php5-pgsql - says no package available - might be a different issue provided I don't have --with-pdo-pgsql in the configure command

Questions
1) Do I have to recompile PHP, if so what is the best way to do it? I never did it before, just don't want to screw anything
2) Can I just get away with installing php5-pgsql?

Thanks very much for your time and help!

User avatar
remirepo
Posts: 342
Joined: 2014/09/21 09:07:12
Location: France
Contact:

Re: Do I have to recompile PHP for adding Postgres PDO suppo

Post by remirepo » 2015/07/03 11:49:53

About the "Configure command", read : http://blog.remirepo.net/post/2010/09/2 ... -or-PEBKAC

For all extensions, if you need "foo", yum install php-foo

So:

Code: Select all

 yum install php-pdo_pgsql
Remi's Repository - Forum - Blog

success17
Posts: 5
Joined: 2015/07/03 07:07:50

Re: Do I have to recompile PHP for adding Postgres PDO suppo

Post by success17 » 2015/07/04 02:58:15

remirepo,

thanks a lot, I have done what you said but having another problem.

Here is what I have done:

1) Excluded php* from yum.xml exclude path
2) ran yum install php-pdo_pgsql
3) added a couple of lines to php.ini:
extension=pdo_pgsql.so
extension=pgsql.so
4) restarted apache (stopped, confirmed it's down, started again)

Still no luck - when I run phpinfo it doesn't show Postgres PDO available. What am I missing please?

Thanks!

success17
Posts: 5
Joined: 2015/07/03 07:07:50

Re: Do I have to recompile PHP for adding Postgres PDO suppo

Post by success17 » 2015/07/04 03:49:31

More info:

1) Checked where extensions are (/usr/local/lib/php/extensions/no-debug-non-zts-20100525)
2) There were no pdo_pgsql.so or pgsql.so extensions there
3) Searched for these files, found them in /usr/lib/php/modules/
4) Changed php.ini as follows:
extension="/usr/lib/php/modules/pdo_pgsql.so"
extension="/usr/lib/php/modules/pgsql.so"

Now I am getting the following errors:

PHP Warning: PHP Startup: pdo_pgsql: Unable to initialize module
Module compiled with module API=20090626
PHP compiled with module API=20100525

Can you please advise what to do from here?

User avatar
remirepo
Posts: 342
Joined: 2014/09/21 09:07:12
Location: France
Contact:

Re: Do I have to recompile PHP for adding Postgres PDO suppo

Post by remirepo » 2015/07/04 05:42:40

1) Checked where extensions are (/usr/local/lib/php/extensions/no-debug-non-zts-20100525)
This is obviously a manually build version, not the packaged one, which cannot be suported here.

And I have miss you are running the old CentOS 5...
Which version do you need ? (look like 5.4...)
Remi's Repository - Forum - Blog

success17
Posts: 5
Joined: 2015/07/03 07:07:50

Re: Do I have to recompile PHP for adding Postgres PDO suppo

Post by success17 » 2015/07/04 06:12:47

remirepo, many thanks for your time and efforts, really appreciate it!

Solved the problem as follows (had to recompile pdo_pgsql):

yum install postgresql-devel - was getting an error in one of the below steps without doing this

The following steps are from the solution described here:
http://stackoverflow.com/questions/6174 ... or-eclipse

pecl download pdo_pgsql
tar xzf PDO_PGSQL-1.0.2.tgz
cd PDO_PGSQL-1.0.2
phpize
./configure --with-pdo-pgsql=/path/to/postgres
make
make install

The above steps compiled the pdo_pgsql extension with the right API version and the extension was added to the correct extension folder.

the only change to the original version of php.ini was 1 extra line (as you can see, there is no need to point to any external extensions anymore):
extension=pdo_pgsql.so

Hope this helps someone in the future.

User avatar
remirepo
Posts: 342
Joined: 2014/09/21 09:07:12
Location: France
Contact:

Re: Do I have to recompile PHP for adding Postgres PDO suppo

Post by remirepo » 2015/07/04 07:59:02

Building from sources is never a good solution.

Especially when pulling sources from PECL of an outdated / unmaintained package (design for PHP 5.0, before it was merged in php-src in 5.1)

(P.S. and especially when various 3rd party repo provides up-to-date package of php 5.4, 5.5, 5.6...)
Remi's Repository - Forum - Blog

success17
Posts: 5
Joined: 2015/07/03 07:07:50

Re: Do I have to recompile PHP for adding Postgres PDO suppo

Post by success17 » 2015/07/04 10:49:16

remerpo,

1) Where can I download a proper version?
2) Should I just replace one file pdo_pgsql.so with the downloaded from a repo?

CentOS release 5.11 (Final)
PHP Version 5.4.25

Thanks again!

Post Reply

Return to “CentOS 5 - Software Support”