在 Mac OS X 上的 PHP 中启用 PostgreSQL 支持 [英] Enabling PostgreSQL support in PHP on Mac OS X
问题描述
我很难让命令pg_connect()"在我的 Mac 上正常工作.我目前正在编写一个 PHP 脚本(从控制台执行)来读取 PostgreSQL 数据库并通过电子邮件发送报告.
I'm having a terribly difficult time getting the command "pg_connect()" to work properly on my Mac. I'm currently writing a PHP script (to be executed from console) to read a PostgreSQL database and email a report.
我已经进入我的 php.ini
文件并添加了
I've gone into my php.ini
file and added
extension=pgsql.so
但是,我遇到了以下错误.
But, I'm met with the following error.
PHP 警告:PHP 启动:无法加载动态库 '/usr/lib/php/extensions/no-debug-non-zts-20090626/php_pgsql.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/php_pgsql.so, 9): 在第 0 行的 Unknown 中找不到图像
PHP 致命错误:调用未定义的函数 pg_connect() in...(此处为废话文件)
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/php_pgsql.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/php_pgsql.so, 9): image not found in Unknown on line 0
PHP Fatal error: Call to undefined function pg_connect() in... (blah file here)
运行 phpinfo()
时,我对 PostgreSQL 一无所知,那么我的问题是什么?
When running phpinfo()
, I see nothing about PostgreSQL, so what is my issue here?
推荐答案
与 OS X 捆绑在一起的 PHP 版本不包括 PostgreSQL.您必须自己编译扩展.以下是一些说明:
The PHP version that comes bundled with OS X doesn't include PostgreSQL. You'll have to compile the extension yourself. Here are some instructions:
- 找到您的 PHP 版本:
php -v
. - 下载与您匹配的 PHP 版本:
curl -O http://us.php.net/distributions/php-5.3.3.tar.gz
.(此示例下载 PHP 5.3.3,但这必须与您的版本匹配) - 解压你下载的档案:
tar -xzvf php-5.3.3.tar.gz
- 切换到PostgreSQL的扩展目录:
cd php-5.3.3/ext/pgsql/
- 输入
phpize
. - 输入
./configure
. - 输入
make
. - 输入
sudo make install
. - 通过添加
extension=pgsql.so
将扩展添加到您的php.ini
文件.(您可能已经这样做了) - 重启 Apache.
- Find your version of PHP:
php -v
. - Download the version of PHP that matches yours:
curl -O http://us.php.net/distributions/php-5.3.3.tar.gz
. (This example downloads PHP 5.3.3 but this must match your version) - Extract the archive you downloaded:
tar -xzvf php-5.3.3.tar.gz
- Change to the PostgreSQL's extension directory:
cd php-5.3.3/ext/pgsql/
- Type
phpize
. - Type
./configure
. - Type
make
. - Type
sudo make install
. - Add the extension to you
php.ini
file by addingextension=pgsql.so
. (You may already have done this) - Restart Apache.
OS X Mountain Lion 的更新Apple 已从较新版本的 XCode 中删除 autoconf
,因此上述过程将在 #5 处失败.解决这个问题:
Update for OS X Mountain Lion
Apple has removed autoconf
from the newer versions of XCode so the procedure above will fail at #5. To solve that problem:
- 输入
/usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
. - 输入
sudo chown -R $USER/usr/local/Cellar
. - 输入
brew update
. - 输入
brew install autoconf
.
那应该安装 autoconf
并允许您使用上述说明安装模块.
That should install autoconf
and allow you to install the module using the instructions above.
这篇关于在 Mac OS X 上的 PHP 中启用 PostgreSQL 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!