views:

592

answers:

3

Hi, I've been tasked to create a PHP app which accesses an existing PostgreSQL database. This is my first time working with Postgre, not to mention the PHP has already been installed in the Linux box on which the app is supposed to run. I have no experience setting up this stuff, I just code.

My question is that I can't seem to get the Postgre extension working in PHP. I checked the php.ini file, there were no "extension=..." lines. So I added "extension=pgsql.so". I then checked the "extension_dir" and found that there were only 2 files in there (ldap.so, phpcups.so), I added a pgsql.so file taken from another Linux box. I restarted httpd. And it does not work. I couldn't find any "pgsql" or "postgre" in phpinfo().

Forgive my noobness. I know too little Linux. I would really appreciate it if you can point me to the right direction.


I used the suggestion given by number5:

Dude, I'm on RedHat. I used the "yum" version of the command you gave, and I got this:

[root@perseus ~]# yum install php-pgsql Loading "installonlyn" plugin Setting up Install Process Setting up repositories Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=5&arch=x86_64&repo=extras error was [Errno 4] IOError: Error: Cannot find a valid baseurl for repo: extras


UNFORTUNATELY, the Linux server I'm using is NOT connected to the Internet. Any other way to install?

+2  A: 

It depends on which Linux distro you are using.

If you are using Ubuntu/Debian, you need to:

sudo apt-get install php5-pgsql

Fedora/CentOS

yum install php-pgsql

usually you can find out which distro you are on by:

ls /etc/*-release
number5
Dude I added some comments above
Obay
+1  A: 
  • Remove the .so file you've copied from the other machine (though it might work, there's no need to take the risk)
  • Use the distribution's package manager to install the php_pgsql/php5_pqsql module
  • Restart the apache and try again. Maybe the module has been added to an .ini file automagically
  • If not, run <?php echo 'ini: ', get_cfg_var('cfg_file_path'); to see which php.ini you have to edit
  • edit this ini file
  • restart the apache
VolkerK
+1  A: 

On CentOS extensions create separate *.ini file one per each php extension in /etc/php.d

So, don't alter main *.ini file, but create /etc/php.d/pgsql.ini and add there a line

extension=pgsql.so

Then you will need to restart Apache using

service httpd restart

But the best automated way is to just type

yum install php-pgsql

In your case that didn't work because of some problems in yum configuration. Go to /etc/yum-repos.d Type

nano /etc/yum.repos.d/CentOS-Base.repo

Scroll down to [extras] section and ensure it is like this:

#additional packages that may be useful
[extras]
priority=1
name=CentOS-$releasever - Extras
=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

Correct it if needed, save file (Ctrl-X) and do the following:

yum clean all
yum upgrade

Afterwards try to repeat

yum install php-pgsql
FractalizeR
it says:Config Error: File contains parsing errors: file://///etc/yum.repos.d/CentOS-Base.repo [line 41]: '=extras\n'
Obay
Who says? What's your CentOS version? May be, you should remove "priority" string?
FractalizeR