Skip to content

Instantly share code, notes, and snippets.

@anxgang
Last active March 6, 2020 02:29
Show Gist options
  • Save anxgang/17779b67868aff9071224d66a1f10eef to your computer and use it in GitHub Desktop.
Save anxgang/17779b67868aff9071224d66a1f10eef to your computer and use it in GitHub Desktop.
mac 安裝 php 的 pgsql extension

mac 安裝 php 的 pgsql extension

因為我的 php 是用 homebrew 安裝的 找不到比較快的方式 只好自己去從源碼編譯

  1. 先確認 php 版本
$ php -v

PHP 7.3.9 (cli)....(略)
  1. 下載該版本的 php 源碼並解壓縮 https://www.php.net/downloads.php

例如放到 ~/Downloads/php-7.3.9

  1. 安裝 autoconf 並 執行 phpize 命令

先安裝 autoconf

brew install autoconf

然後進入源碼目錄底下 ~/Downloads/php-7.3.9/ext/pgsql 執行

phplize

成功會顯示

Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731
  1. 然後輸入
./configure
  1. 接下來就會在 ~/Downloads/php-7.3.9/ext/pgsql/modules 看到 pgsql.so
  2. 將其複製到 php ext 的目錄(可以用 phpinfo() 去查)
/Users/anxgang/.phpenv/versions/7.3.9/lib/php/extensions/no-debug-non-zts-20180731
  1. 然後需要再把 php.ini 裡面 pgsql extension 註解打開 (同樣用 phpinfo() 去查位置)
/Users/anxgang/.phpenv/versions/7.3.9/etc/php.ini

找到

;extension=pgsql

將其改為

extension=pgsql
  1. 重開 server

參考

https://www.jianshu.com/p/1e5ab6122d08

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment