简体   繁体   English

pgsql.so未在PHP中加载

[英]pgsql.so is not loaded in PHP

I've been tasked to create a PHP app which accesses an existing PostgreSQL database. 我的任务是创建一个访问现有PostgreSQL数据库的PHP应用程序。 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. 这是我第一次使用Postgre,更不用说PHP已经安装在应该运行应用程序的Linux机器中。 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. 我的问题是我似乎无法使用PHP进行Postgre扩展。 I checked the php.ini file, there were no "extension=..." lines. 我检查了php.ini文件,没有“extension = ...”行。 So I added "extension=pgsql.so". 所以我添加了“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. 然后我检查了“extension_dir”,发现那里只有2个文件(ldap.so,phpcups.so),我添加了一个从另一个Linux盒子中取出的pgsql.so文件。 I restarted httpd. 我重启了httpd。 And it does not work. 它不起作用。 I couldn't find any "pgsql" or "postgre" in phpinfo(). 我在phpinfo()中找不到任何“pgsql”或“postgre”。

Forgive my noobness. 原谅我的无知。 I know too little Linux. 我知道Linux太少了。 I would really appreciate it if you can point me to the right direction. 如果你能指出我正确的方向,我将非常感激。


I used the suggestion given by number5: 我使用了number5给出的建议:

Dude, I'm on RedHat. 伙计,我在RedHat上。 I used the "yum" version of the command you gave, and I got this: 我使用了你给出的命令的“yum”版本,我得到了这个:

[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 [root @ perseus~] #yum install php-pgsql加载“installonlyn”插件设置安装过程设置存储库无法检索镜像列表http://mirrorlist.centos.org/?release=5&arch=x86_64&repo=extras错误是[Errno 4] IOError:错误:无法为repo:extras找到有效的baseurl


UNFORTUNATELY, the Linux server I'm using is NOT connected to the Internet. 不幸的是,我正在使用的Linux服务器没有连接到Internet。 Any other way to install? 还有其他安装方法吗?

It depends on which Linux distro you are using. 这取决于您使用的是哪个Linux发行版。

If you are using Ubuntu/Debian, you need to: 如果您使用的是Ubuntu / Debian,则需要:

sudo apt-get install php5-pgsql

Fedora/CentOS Fedora的/ CentOS的

yum install php-pgsql

usually you can find out which distro you are on by: 通常你可以找到你所在的发行版:

ls /etc/*-release

On CentOS extensions create separate *.ini file one per each php extension in /etc/php.d 在CentOS扩展上,在/etc/php.d中为每个php扩展创建一个单独的* .ini文件

So, don't alter main *.ini file, but create /etc/php.d/pgsql.ini and add there a line 所以,不要改变main * .ini文件,而是创建/etc/php.d/pgsql.ini并添加一行

extension=pgsql.so

Then you will need to restart Apache using 然后你需要重启Apache

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. 在您的情况下由于yum配置中的一些问题而无效。 Go to /etc/yum-repos.d Type 转到/etc/yum-repos.d类型

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

Scroll down to [extras] section and ensure it is like this: 向下滚动到[extras]部分并确保它是这样的:

#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: 如果需要,请更正它,保存文件(Ctrl-X)并执行以下操作:

yum clean all
yum upgrade

Afterwards try to repeat 然后尝试重复

yum install php-pgsql
  • Remove the .so file you've copied from the other machine (though it might work, there's no need to take the risk) 删除您从其他计算机复​​制的.so文件(虽然它可能有效,但不需要承担风险)
  • Use the distribution's package manager to install the php_pgsql/php5_pqsql module 使用发行版的包管理器安装php_pgsql / php5_pqsql模块
  • Restart the apache and try again. 重启apache并重试。 Maybe the module has been added to an .ini file automagically 也许该模块已自动添加到.ini文件中
  • If not, run <?php echo 'ini: ', get_cfg_var('cfg_file_path'); 如果没有,运行<?php echo 'ini: ', get_cfg_var('cfg_file_path'); to see which php.ini you have to edit 看看你要编辑哪个php.ini
  • edit this ini file 编辑这个ini文件
  • restart the apache 重启apache

My operation system Linux mint kde and there was same issue 我的操作系统Linux薄荷kde和同样的问题

pg_connect() pg_connect()

You must install if you are use php5.6 如果您使用的是php5.6,则必须安装

sudo apt-get install php5.6-pgsql

After you must change extention name in "php.ini" file. 必须在“php.ini”文件中更改扩展名后。

;extension=php_pgsql.dll

'dll' to 'so' 'dll'到'so'

For example 例如

extension=php_pgsql.so

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM