MAC系統下phpstorm不能基於MAXP使用MongoDB的結局辦法

一天的整理,僅供參考!

$a=new Mongo();
上述代碼執行時會報錯,如下所示:

Fatal error: Class 'Mongo' not found in /Users/mfw/PhpstormProjects/KeenSting/control/exprement.php on line 17

我安裝的是MAMP集成開發環境

phpstorm中的配置如下


查了很久的資料才發現是MAMP中的php沒有擴展mongodb功能,系統自帶的php我倒是撞了mongodb但是因爲缺少php-cgi,所以根本沒什麼卵用--網頁直接輸入localhost:27017可以接入mac自帶的php所擴展的mongo,而phpstorm職能連mamp,mamp沒有mongo,所以就要給他裝上

開始安裝


1,這裏要用到brew安裝,沒有的可以去度娘找找homebrew安裝的教程,比較快,但是需要XCODE的支持,沒有的去applestore down一個吧,免費,安裝完需要啓動一次再退出


2,安裝mongodb(需要root權限  控制檯輸入sudo -s,回車後輸入密碼即可)
bash-3.2# /Applications/MAMP/bin/php/php5.6.10/bin/pecl install mongo
結果出錯
downloading mongo-1.6.10.tgz ...
Starting to download mongo-1.6.10.tgz (209,087 bytes)
.............................................done: 209,087 bytes
118 source files, building
running: phpize
grep: /Applications/MAMP/bin/php/php5.6.10/include/php/main/php.h: No such file or directory
grep: /Applications/MAMP/bin/php/php5.6.10/include/php/Zend/zend_modules.h: No such file or directory
grep: /Applications/MAMP/bin/php/php5.6.10/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

ERROR: `phpize' failed

3,找到include文件夾(軟連接,關聯文件夾)

bash-3.2# sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include /Applications/MAMP/bin/php/php5.6.10/include

再次運行
結果還是有問題
bash-3.2# /Applications/MAMP/bin/php/php5.6.10/bin/pecl install mongo
downloading mongo-1.6.10.tgz ...
Starting to download mongo-1.6.10.tgz (209,087 bytes)
.............................................done: 209,087 bytes
118 source files, building
running: phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

ERROR: `phpize' failed

4,說是找不到autoconfig,那就安裝!!(這裏要退出root狀態)
KeenStings-MacBook-Pro:~ mfw$ brew install autoconf
Warning: You have an outdated version of /usr/bin/install_name_tool installed.
This will cause binary package installations to fail.
This can happen if you install osx-gcc-installer or RailsInstaller.
To restore it, you must reinstall OS X or restore the binary from
the OS packages.
==> Downloading https://homebrew.bintray.com/bottles/autoconf-2.69.yosemite.bott
######################################################################## 100.0%
==> Pouring autoconf-2.69.yosemite.bottle.1.tar.gz
�  /usr/local/Cellar/autoconf/2.69: 70 files, 3.1M

5,安裝完了執行 
KeenStings-MacBook-Pro:~ mfw$ sudo /Applications/MAMP/bin/php/php5.6.10/bin/pecl install mongo

提示
Password:
downloading mongo-1.6.10.tgz ...
Starting to download mongo-1.6.10.tgz (209,087 bytes)
..........................................done: 209,087 bytes
118 source files, building
running: phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
Build with Cyrus SASL (MongoDB Enterprise Authentication) support? [no]

6,輸入yes回車就好了

很長一段提示信息
最後是這個
Build process completed successfully
Installing '/Applications/MAMP/bin/php/php5.6.10/lib/php/extensions/no-debug-non-zts-20131226/mongo.so'
install ok: channel://pecl.php.net/mongo-1.6.10
configuration option "php_ini" is not set to php.ini location
You should add "extension=mongo.so" to php.ini
KeenStings-MacBook-Pro:~ mfw$

7,到你的位置去吧php.ini中加入extension=mongo.so  即可


看教程就一回,但是我找了一天的資料==



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章