MongoDB 的php 驱动的安装
第一步:下载MongoDB的php驱动
下载地址:https://github.com/mongodb/mongo-php-driver
1 | wget -O mongo-php-driver-master.zip https://github.com/mongodb/mongo-php-driver/archive/master.zip |
第二步:解压
1 | unzip mongo-php-driver-master.zip |
第三步:安装
1 | cd mongo-php-driver-master/ |
会出现类似
1 | Installing shared extensions: /usr/lib/php5/20090626+lfs/ |
或者是
1 | Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/ |
表示安装成功
确保和运行的 PHP 是同一个扩展目录:
1 | $ php -i | grep extension_dir |
输出的结果如:
1 | extension_dir => /usr/lib/php/extensions/no-debug-zts-20060613 =>/usr/lib/php/extensions/no-debug-zts-20060613 |
如果不一致,则需要修改 php.ini 里的 extension_dir,或者把 mongo.so 移过去。
第四步:添加momgoDB扩展
打开php.ini
加入
1 | extension=mongo.so |
然后重新启动php-fpm
这里我遇到了一个问题:
1 | php-fpm restart |
这几个命令似乎都木有用了。执行完后,总是提示我
Usage: php [-n] [-e] [-h] [-i] [-m] [-v] [-t] [-p
] [-g ] [-c ] [-d foo[=bar]] [-y ] -c
| Look for php.ini file in this directory -n No php.ini file will be used
-d foo[=bar] Define INI entry foo with value ‘bar’
-e Generate extended information for debugger/profiler
-h This help
-i PHP information
-m Show compiled in modules
-v Version number
-p, –prefix
Specify alternative prefix path to FastCGI process manager (default: /usr/local/php).
-g, –pid
Specify the PID file location.
-y, –fpm-config
Specify alternative path to FastCGI process manager config file.
-t, –test Test FPM configuration and exit
-R, –allow-to-run-as-root
Allow pool to run as root (disabled by default)
受不了,来点强制的措施吧
先kill所有的php-fpm的进程,然后直接执行
1 | php-fpm |
如果php-fpm的进程只有3,5个还好说,但是如果有几十个的话,我是觉得有点累:
试试下面这个脚本吧
1 |
|
或者是
1 |
|
因为之前的那个是Ubuntu系统的,后面的这个是Centos系统的
然后输出phpinfo,搜索一下mongo,是不是已经存在了,如果还是木有的话,请留言