以下提供一種安裝PHP mongodb擴展的方式 pecl
網(wǎng)上說不推薦使用pecl安裝PHP擴展
但是當(dāng)你使用brew ,wget方式安裝都失敗的時候,還一直找不到解決的辦法,可以試一試pecl安裝
首先macOS上安裝pecl
繼續(xù)附上原文鏈接
http://www.mayanlong.com/archives/2018/pear.html
為防止鏈接失效,方便閱讀,在下面繼續(xù)寫一份
簡介
PECL(The PHP Extension Community Library)是 PHP 擴展的存儲庫,為 PHP 所有的擴展提供提供托管和下載服務(wù)。
通過 PEAR(PHP Extension and Application Repository)的 Package Manager 的安裝管理方式,可以對 PECL 擴展進行下載和安裝。
安裝
官方提供了 PEAR 在各個平臺的安裝方式,直接看官方文檔的請進【傳送門】,macOS 平臺官方安裝翻譯如下。
1.下載PEAR
使用 curl 命令下載即可:
$ curl -O https://pear.php.net/go-pear.phar
2.安裝PEAR
使用 sudo 授權(quán)進行安裝:
$ sudo php -d detect_unicode=0 go-pear.phar
安裝過程需要進行簡單的配置,如下:
Below is a suggested file layout for your new PEAR installation. To
change individual locations, type the number in front of the
directory. Type 'all' to change all of them or simply press Enter to
accept these locations.
1. Installation base ($prefix) : /usr
2. Temporary directory for processing : /tmp/pear/install
3. Temporary directory for downloads : /tmp/pear/install
4. Binaries directory : /usr/bin
5. PHP code directory ($php_dir) : /usr/share/pear
6. Documentation directory : /usr/docs
7. Data directory : /usr/data
8. User-modifiable configuration files directory : /usr/cfg
9. Public Web Files directory : /usr/www
10. System manual pages directory : /usr/man
11. Tests directory : /usr/tests
12. Name of configuration file : /private/etc/pear.conf
1-12, 'all' or Enter to continue: 1
輸入 1,將安裝根目錄修改為 /usr/local/pear;
輸入 4,將命令安裝到 /usr/local/bin 目錄;
其它選項默認(rèn)即可,一路回車。
3.檢查安裝是否成功
出現(xiàn)如下結(jié)果,則安裝成功:
$ pear version
PEAR Version: 1.10.5
PHP Version: 7.1.7
Zend Engine Version: 3.1.0
安裝mongodb擴展
找到pecl位置
$ find / -name pecl
我的位置是
/usr/local/bin/pecl
安裝mongodb
$ sudo /usr/local/bin/pecl install mongodb
安裝成功之后,會有mongdb.so擴展
Build process completed successfully
Installing '/usr/lib/php/extensions/no-debug-non-zts-20131226/mongodb.so'
install ok: channel://pecl.php.net/mongodb-1.5.2
configuration option "php_ini" is not set to php.ini location
You should add "extension=mongodb.so" to php.ini
去檢查一下擴展下載成功了沒有
$ ls /usr/lib/php/extensions/no-debug-non-zts-20131226/
發(fā)現(xiàn)有mongodb.so,去php.ini文件中添加擴展
$ sudo vim /etc/php.ini
在php.ini文件中添加
extension=mongodb.so
擴展安裝成功,重啟一下php-fpm
查看有沒有mongodb擴展
$ php -m | grep mongodb