pgsql.so 未在 PHP 中加载

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2832545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:48:44  来源:igfitidea点击:

pgsql.so is not loaded in PHP

phpapachephp-extension

提问by Obay

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.

我的任务是创建一个访问现有 PostgreSQL 数据库的 PHP 应用程序。这是我第一次使用 Postgre,更不用说 PHP 已经安装在应该运行该应用程序的 Linux 机器中了。我没有设置这些东西的经验,我只是编码。

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().

我的问题是我似乎无法在 PHP 中使用 Postgre 扩展。我检查了 php.ini 文件,没有“extension=...”行。所以我添加了“extension=pgsql.so”。然后我检查了“extension_dir”,发现里面只有 2 个文件(ldap.so、phpcups.so),我添加了一个从另一个 Linux 机器上获取的 pgsql.so 文件。我重新启动了httpd。它不起作用。我在 phpinfo() 中找不到任何“pgsql”或“postgre”。

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

原谅我的菜鸟。我对Linux了解太少了。如果您能指出我正确的方向,我将不胜感激。



I used the suggestion given by number5:

我使用了 number5 给出的建议:

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

伙计,我在 RedHat 上。我使用了你给出的命令的“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=extraserror was [Errno 4] IOError: Error: Cannot find a valid baseurl for repo: extras

[root@perseus ~]# yum install php-pgsql Loading "installonlyn" plugin Setting up Install Process Setting up repositories 无法检索镜像列表http://mirrorlist.centos.org/?release=5&arch=x86_64&repo=extraserror was [Errno 4] IOError: 错误: 找不到有效的 repo baseurl: extras



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

不幸的是,我使用的 Linux 服务器未连接到 Internet。还有什么安装方法吗?

采纳答案by number5

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

回答by Vladislav Rastrusny

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

所以,不要改变主 *.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. Go to /etc/yum-repos.d Type

在您的情况下,由于 yum 配置中的一些问题而不起作用。转到 /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

回答by VolkerK

  • 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
  • 删除您从另一台机器复制的 .so 文件(虽然它可能有效,但无需冒险)
  • 使用发行版的包管理器安装 php_pgsql/php5_pqsql 模块
  • 重新启动 apache 并重试。也许该模块已自动添加到 .ini 文件中
  • 如果没有,请运行<?php echo 'ini: ', get_cfg_var('cfg_file_path');以查看您必须编辑哪个 php.ini
  • 编辑这个ini文件
  • 重启apache

回答by Vugar Dadalov

My operation system Linux mint kde and there was same issue

我的操作系统 Linux mint 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