Postgresql 为postgres Ubuntu安装pdo

Postgresql 为postgres Ubuntu安装pdo,postgresql,pdo,Postgresql,Pdo,我试图为我的php安装启用pdo驱动程序,但是当我运行命令时 ./configure --prefix=/usr/local/webserver/php --with-apxs2=/usr/local/webserver/apache2/bin/apxs --enable-mbstring --enable-intl --with-icu-dir=/usr --with-pgsql=/usr/local/webserver/postgres --with-pdo-pgsql=/usr/local

我试图为我的php安装启用pdo驱动程序,但是当我运行命令时

./configure --prefix=/usr/local/webserver/php --with-apxs2=/usr/local/webserver/apache2/bin/apxs --enable-mbstring --enable-intl --with-icu-dir=/usr --with-pgsql=/usr/local/webserver/postgres --with-pdo-pgsql=/usr/local/webserver/postgres
我明白了

我在那个目录中安装了postgresql

/usr/local/webserver/postgres

我使用bin软件包安装了postgresql 9.0.4.1,并使用PHP5.3尝试使用打包的pecl版本(打包安装的优点是更易于升级):

或者,如果您只需要一个PHP驱动程序,但不一定是PDO驱动程序:

apt-get install php5-pgsql

否则,该消息很可能意味着您需要安装更新的libpq包。 您可以通过运行以下命令来检查您的版本:

dpkg -s libpq-dev

PostgreSQL的PDO驱动程序现在包含在debian包php5-dev中。使用Pecl的上述步骤不再有效。

Pecl PDO包现在已不推荐使用。顺便说一句,debian软件包php5 pgsql现在包括常规驱动程序和PDO驱动程序,因此:

apt-get install php-pgsql
在站点可以使用Apache之前,还需要重新启动Apache:

sudo systemctl restart apache2

如果您正在将出色的
ondrej/php
ubuntu存储库与php7.0一起使用:

sudo apt-get install php7.0-pgsql
对于带有php7.1的
ondrej/php
Ubuntu存储库:

sudo apt-get install php7.1-pgsql
相同的存储库,但对于php5.6:

sudo apt-get install php5.6-pgsql

简洁易记。我喜欢这个存储库。

如果您使用的是PHP5.6,那么命令是:

sudo apt-get install php5.6-pgsql

我不确定这个软件包是否包含PDO驱动程序。谢谢记住执行:
php5enmod pgsql
之后,还需要重新启动您的web服务器。我不记得当时我是如何解决的,但我现在可以说的是,对于Debian和Ubuntu来说,@alex说的是正确的安装方式。但是我必须说,Ubuntu的版本,比如14版,或者更早的版本,已经包括了Postgres(我认为是9.0版)如果你想安装一个像9.3这样的新版本,你可以使用apt-get-purge-postgresql-y&&apt-get-install-postgresql-9.3-y请注意这个答案已经过时了,请看下面威尔的答案。这是给我的——我花了好几个小时在Laravel Homesteadno probem的墙上敲着头说:“[PDOException]找不到驱动程序”,但真正要感谢的是昂德雷。他/她让PHP的安装变得如此简单,这让安装变得非常简单,只需执行php7.3-pgsql。干杯
sudo apt-get install php5.6-pgsql
sudo apt-get install php5.6-pgsql