在Mac OS X上的PHP中启用PostgreSQL支持 [英] Enabling PostgreSQL support in PHP on Mac OS X
问题描述
我很难在Mac上正常使用命令"pg_connect()".我目前正在编写一个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
文件并添加了
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行的未知"中找不到图像
PHP致命错误:在...(此处为空白文件)中调用未定义的函数pg_connect()
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
.
- Type
/usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
. - Type
sudo chown -R $USER /usr/local/Cellar
. - Type
brew update
. - Type
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屋!