在 Mac 上为 PostgreSQL 安装 PDO 驱动程序(使用 Zend for eclipse)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/61747/
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-09-10 18:22:35  来源:igfitidea点击:

Installing PDO-drivers for PostgreSQL on Mac (using Zend for eclipse)

eclipsemacospostgresqlpdo

提问by Vargen

How can I get PDO to work on my mac (os x 10.5)? I'm using the built in php and php in Zend/Eclipse. Can't seem to find useful drivers for it at all.

如何让 PDO 在我的 mac (os x 10.5) 上工作?我在 Zend/Eclipse 中使用内置的 php 和 php。似乎根本找不到有用的驱动程序。

回答by hbw

I had to install the PDO_PGSQL driver recently on Leopard, and I ran across a multitude of problems. In my search for answers, I stumbled across this question. Now I have it successfully installed, and so, even though this question is quite old, I hope that what I've found can help others (like myself) who will undoubtedly run into similar problems.

我最近不得不在 Leopard 上安装 PDO_PGSQL 驱动程序,但遇到了很多问题。在寻找答案的过程中,我偶然发现了这个问题。现在我已经成功安装了它,所以,即使这个问题已经很老了,我希望我发现的东西可以帮助那些无疑会遇到类似问题的人(比如我自己)。

The first thing you'll need to do is install PEAR, if you haven't done so already, since it doesn't come installed on Leopard by default.

您需要做的第一件事是安装 PEAR,如果您还没有这样做的话,因为它默认没有安装在 Leopard 上。

Once you do that, use the PECL installer to download the PDO_PGSQL package:

完成后,使用 PECL 安装程序下载 PDO_PGSQL 包:

$ pecl download pdo_pgsql
$ tar xzf PDO_PGSQL-1.0.2.tgz

(Note: you may have to run peclas the superuser, i.e. sudo pecl.)

(注意:您可能必须以pecl超级用户身份运行,即sudo pecl。)

After that, since the PECL installer can't install the extension directly, you'll need to build and install it yourself:

之后,由于 PECL 安装程序无法直接安装扩展,您需要自己构建和安装它:

$ cd PDO_PGSQL-1.0.2
$ phpize
$ ./configure --with-pdo-pgsql=/path/to/your/PostgreSQL/installation
$ make && sudo make install

If all goes well, you should have a file called "pdo_pgsql.so" sitting in a directory that should look something like "/usr/lib/php/extensions/no-debug-non-zts-20060613/" (the PECL installation should have outputted the directory it installed the extension to).

如果一切顺利,你应该有一个名为“文件pdo_pgsql.so”坐在一个目录应该是这个样子“ /usr/lib/php/extensions/no-debug-non-zts-20060613/”(PECL电安装应该已经输出它安装扩展的目录)。

To finalize the installation, you'll need to edit your php.inifile. Find the section labeled "Dynamic Extensions", and underneath the list of (probably commented out) extensions, add this line:

要完成安装,您需要编辑php.ini文件。找到标有“动态扩展”的部分,并在(可能已注释掉的)扩展列表下方添加以下行:

extension=pdo_pgsql.so

Now, assuming this is the first time you've installed PHP extensions, there are two additional steps you need to take in order to get this working. First, in php.ini, find the extension_dirdirective (under "Paths and Directories"), and change it to the directory that the pdo_pgsql.sofile was installed in. For example, my extension_dirdirective looks like:

现在,假设这是您第一次安装 PHP 扩展,您需要执行两个额外的步骤才能使其正常工作。首先,在 中php.ini,找到extension_dir指令(在“路径和目录”下),并将其更改pdo_pgsql.so为安装文件的目录。例如,我的extension_dir指令如下所示:

extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20060613"

The second step, if you're on a 64-bit Intel Mac, involves making Apache run in 32-bit mode. (If there's a better strategy, I'd like to know, but for now, this is the best I could find.) In order to do this, edit the property list file located at /System/Library/LaunchDaemons/org.apache.httpd.plist. Find these two lines:

第二步,如果您使用的是 64 位 Intel Mac,则涉及让 Apache 在 32 位模式下运行。(如果有更好的策略,我想知道,但就目前而言,这是我能找到的最佳策略。)为此,请编辑位于/System/Library/LaunchDaemons/org.apache.httpd.plist. 找到这两行:

<key>ProgramArguments</key>
<array>

Under them, add these three lines:

在它们下面,添加以下三行:

<string>arch</string>
<string>-arch</string>
<string>i386</string>

Now, just restart Apache, and PDO_PGSQL will be up and running.

现在,只需重新启动 Apache,PDO_PGSQL 就会启动并运行。

回答by Wilco

Take a look at this PECL package: PDO_PGSQL

看看这个 PECL 包:PDO_PGSQL

I haven't tried it myself, but I've been interested in playing with Postgres as an alternative to MySQL. If I have a chance to try it soon, I'll throw my results up here in case it helps.

我自己没有尝试过,但我一直有兴趣使用 Postgres 作为 MySQL 的替代品。如果我有机会很快尝试一下,我会把我的结果扔在这里以防万一。

回答by yongrui

Install new php version via brew and restart server, and php -v, all issues are removed.

通过 brew 安装新的 php 版本并重新启动服务器,以及 php -v,所有问题都已消除。

回答by Alan

I'm not sure this will help with the PDO drivers specifically, but you might look into BitNami's MAPPStack.

我不确定这对 PDO 驱动程序是否有帮助,但您可以查看BitNami 的 MAPPStack

I had a ton of trouble with Postgres, PHP, and Apache on my Mac, some of it having to do with 64- vs 32-bit versions of some or all of them. So far, the BitNami MAPPStack install is working nicely in general. Maybe it will help with your PDO issues as well.

我在 Mac 上使用 Postgres、PHP 和 Apache 遇到了很多麻烦,其中一些与 64 位和 32 位版本的部分或全部有关。到目前为止,BitNami MAPPStack 安装总体上运行良好。也许它也有助于解决您的 PDO 问题。

回答by Mark Horgan

This is what worked for me

这对我有用

brew install php55-pdo-pgsql

This installs PHP 5.5.32 and PostgreSQL 9.5. I already had PostgreSQL 9.4 installed so I uninstalled the homebrew version with:

这将安装 PHP 5.5.32 和 PostgreSQL 9.5。我已经安装了 PostgreSQL 9.4,所以我卸载了自制版本:

brew uninstall postgres

You then have to update /etc/apache2/httpd.conf to point to the correct PHP version and restart Apache:

然后您必须更新 /etc/apache2/httpd.conf 以指向正确的 PHP 版本并重新启动 Apache:

LoadModule php5_module /usr/local/Cellar/php55/5.5.32/libexec/apache2/libphp5.so

My OSX version is Yosemite.

我的 OSX 版本是优胜美地。