PHP 中未加载 pgsql.so

发布于 2024-09-01 16:20:10 字数 863 浏览 6 评论 0原文

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

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

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


我使用了 number5 给出的建议:

老兄,我在 RedHat 上。我使用了你给出的命令的“yum”版本,我得到了这个:

[root@perseus ~]# yum install php-pgsql 加载“installonlyn”插件 设置安装过程 设置存储库 无法检索镜像列表 http://mirrorlist.centos.org/?release =5&arch=x86_64&repo=extras 错误是 [错误号 4] IO 错误: 错误:无法找到存储库的有效基本 URL:额外内容


不幸的是,我使用的 Linux 服务器未连接到互联网。还有其他方式安装吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦纸 2024-09-08 16:20:10

这取决于您使用的 Linux 发行版。

如果您使用 Ubuntu/Debian,您需要:

sudo apt-get install php5-pgsql

Fedora/CentOS

yum install php-pgsql

通常您可以通过以下方式找到您使用的发行版:

ls /etc/*-release

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
放低过去 2024-09-08 16:20:10

在 CentOS 扩展上,在 /etc/php.d 中为每个 php 扩展创建单独的 *.ini 文件,

因此,不要更改主 *.ini 文件,而是创建 /etc/php.d/pgsql.ini 并在其中添加一行

extension=pgsql.so

然后,您需要使用以下命令重新启动 Apache

service httpd restart

但最好的自动化方法是仅键入

yum install php-pgsql

在您的情况下,由于 yum 配置中的一些问题,该方法不起作用。转到/etc/yum-repos.d
类型

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

向下滚动到 [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

如果需要,请更正它,保存文件 (Ctrl-X) 并执行以下操作:

yum clean all
yum upgrade

然后尝试重复

yum install php-pgsql

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
黯然 2024-09-08 16:20:10
  • 删除从其他计算机复​​制的 .so 文件(尽管它可能有效,但无需冒这个风险)
  • 使用发行版的包管理器安装 php_pgsql/php5_pqsql 模块
  • 重新启动 apache 并重试。也许该模块已自动添加到 .ini 文件中
  • 如果没有,请运行 来查看您必须编辑哪个 php.ini
  • 编辑这个ini文件
  • 重启apache
  • 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
拧巴小姐 2024-09-08 16:20:10

我的操作系统 Linux mint kde 也有同样的问题

pg_connect()

如果您使用php5.6,则必须安装。

sudo apt-get install php5.6-pgsql

之后您必须在“php.ini”文件中更改扩展名称。

;extension=php_pgsql.dll

'dll' 到 'so'

例如,

extension=php_pgsql.so

My operation system Linux mint kde and there was same issue

pg_connect()

You must install if you are use php5.6

sudo apt-get install php5.6-pgsql

After you must change extention name in "php.ini" file.

;extension=php_pgsql.dll

'dll' to 'so'

For example

extension=php_pgsql.so
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文