LoginSignup
3
3

More than 5 years have passed since last update.

CentOSでPDOのPostgreSQLを使用する(Vagrant)

Last updated at Posted at 2016-03-27

PDOでPostgreSQLを使用しようとしたところ,以下のようなエラーが出ました.

PHP Fatal error:  Uncaught exception 'PDOException' with message 'could not find driver' in /var/www/html/test/postgis_test.php:8
Stack trace:
#0 /var/www/html/test/postgis_test.php(8): PDO->__construct('pgsql:host=133....', 'postgres', 'TYoshino45!!')
#1 {main}
  thrown in /var/www/html/test/postgis_test.php on line 8

バージョン一覧
- Vagrant: 1.8.1
- CentOS: CentOS release 6.7 (Final)
- PHP: PHP 5.6.12 (cli) (built: Feb 17 2016 03:38:02)

自分はVagrant上で動かしているので,その上でのコマンドになります.
管理者で実行している前提です.

$ vagrant ssh
# sudo su

PECL上の最新版は1.0.2なので,これをインストールします.
PECL :: Package :: PDO_PGSQL
/usr/local/src/の中にインストールします.

# cd /usr/local/src/
# wget http://pecl.php.net/get/PDO_PGSQL-1.0.2.tgz
# tar -xf PDO_PGSQL-1.0.2.tgz
# cd PDO_PGSQL-1.0.2

makeします.

# phpize
# ./configure --with-pdo-pgsql
# make
# make install

php.iniを変更します.
php.iniの場所は以下のコマンドで確認できます.

# php -i | grep php.ini

modulesの下にpdo_pgsql.soというファイルが追加されているはずなので,これをphp.iniに追加します.

# vi php.ini
php.ini
; PostgreSQL
extension_dir = /usr/local/src/PDO_PGSQL-1.0.2/modules/
extension = pdo_pgsql.so

apacheを再起動

# /etc/init.d/httpd restart

参考
phpenv で入れた PHP に pdo_pgsql をインストール LANCARD.LAB|ランカードコムのスタッフブログ
ソースコンパイルしたPHPに後からpdo_pgsqlをインストールする - 知識の引き出し

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3