使用.pgpass Apache的libphp5.so [英] Using .pgpass from Apache libphp5.so

查看:156
本文介绍了使用.pgpass Apache的libphp5.so的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正努力让我们的Apache PHP模块使用PostgreSQL的.pgpass文件中查找数据库连接的密码。我们一直无法得到它的工作。是否有某种限制或错误的这是$ P $从工作pventing呢?

We are trying to get our Apache PHP module to use the PostgreSQL .pgpass file for looking up passwords for database connections. We have been unable to get it to work. Is there some kind of limitation or bug that's preventing this from working?

下面是我们有什么,我们已经检查。这一切都在FreeBSD 10.1。

Here is what we have and what we have checked. This is all on FreeBSD 10.1.

作为命令行预计所有工程。也就是说,测试正是除了PHP可执行同样是/ usr / local / bin目录/ PHP的,而不是Apache的PHP模块。

All works as expected from the command line. That is, the test is exactly the same except for the PHP executable is /usr/local/bin/php instead of the Apache PHP module.

我们已经通过的phpinfo(认证),该Apache和命令线按照相同构建为可能的,包括使用相同的共享库,和相同的php.ini文件

We have verified via phpinfo() that both Apache and command line are built as identically as possible including using the same shared libraries, and the same php.ini file.

Apache的版本2.2.29

Apache version 2.2.29


  • /usr/local/libexec/apache22/libphp5.so

  • /usr/local/lib/php/20100525/pgsql.so

命令行版本的PHP 38年4月5日

Command line PHP version 5.4.38


  • 在/ usr / local / bin目录/ PHP

  • /usr/local/lib/php/20100525/pgsql.so

在这两种情况下,我们设置环境变量PGPASSFILE为相同的值,并验证它是在PHP中正确的。

In both cases, we set the environment variable PGPASSFILE to the same value and verify that it is correct from within PHP.

在这两种情况下,我们使用的是相同的Unix用户名(WWW),所以我们肯定它不是一个文件路径或权限问题。

In both cases, we are using the same Unix username ('www'), so we are sure it is not a file path or permissions problem.

我们只有一个在我们的系统PostgreSQL库,在/usr/local/lib/libpq.so。这是应该发生.pgpass文件使用二进制文件。

We have only one PostgreSQL library on our system, at /usr/local/lib/libpq.so. This is the binary where the .pgpass file usage should occur.

有没有其他人遇到这个问题?是否有我们忽视的东西?

Has anyone else encountered this problem? Is there something we are overlooking?

请问Apache的libphp5.so莫名其妙PHP库pgsql.so旁路使用和直接调用libpq.so,尽管它被配置为使用相同的PHP共享库目录(例如/ usr / local / lib目录/ PHP / 20100525 / )?

Does Apache's libphp5.so somehow bypass usage of the PHP library pgsql.so and call libpq.so directly, despite it being configured to use the same PHP shared library directory (i.e. /usr/local/lib/php/20100525/)?

推荐答案

尽管PHP有 PGPASSFILE 它来自Apache继承,由<$ C $为证明环境C> GETENV(PGPASSFILE),看来这个环境是不是一个可用来最终处理的共享的libpq .pgpass 。这就是为什么这个设置​​被忽略。

Even though php has PGPASSFILE in the environment it inherits from apache, as proven by getenv("PGPASSFILE"), it appears that this environment is not the one that's available to the shared libpq library that ultimately handles .pgpass. This is why this setting gets ignored.

一个解决方法是在连接到数据库之前reput到环境中已经存在的变量,在PHP中:

A workaround is to reput into the environment the variable that's already there, in php before connecting to the database:

if (getenv("PGPASSFILE")!="")
  putenv("PGPASSFILE=".getenv("PGPASSFILE"));

显式传给putenv 将推动可变的方式,使其可用于的libpq 的通话的getenv()。这很奇怪,因为通常一个进程只有一个环境,但它似乎工作。

The explicit putenv will push the variable in a way that makes it available to libpq's calls of getenv(). This is weird since normally a process has only one environment, but it appears to work.

我问了一下扩展,并在一个单独的问题PHP的核心之间的不和谐的环境问题:
为什么putenv()函数需要对已定义的环境变量?

I've asked about the discordant environment problem between extensions and php's core in a separate question: Why is putenv() needed on an already defined environment variable?

这篇关于使用.pgpass Apache的libphp5.so的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆