php打扩展,支持mongodb
既然打扩展,直接上php扩展的网站:
http://pecl.php.net/package/mongodb
选择对应的版本,
进行下载,并安装
或者直接在 linux 命令行中执行:
wget http://pecl.php.net/get/mongodb-1.5.1.tgz tar -xf mongodb-1.5.1.tgz cd mongodb-1.5.1 #在mongodb中是没有configure的,需要使用phpize生成 /usr/local/php/php7/bin/phpize #生成完毕后 ./configure --with-php-config=/usr/local/php/php7/bin/php-config 然后执行: make && meke install /bin/sh /usr/local/src/mongodb-1.5.1/libtool --mode=install cp ./mongodb.la /usr/local/src/mongodb-1.5.1/modules cp ./.libs/mongodb.so /usr/local/src/mongodb-1.5.1/modules/mongodb.so cp ./.libs/mongodb.lai /usr/local/src/mongodb-1.5.1/modules/mongodb.la PATH="$PATH:/sbin" ldconfig -n /usr/local/src/mongodb-1.5.1/modules ---------------------------------------------------------------------- Libraries have been installed in: /usr/local/src/mongodb-1.5.1/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the `LD_RUN_PATH' environment variable during linking - use the `-Wl,--rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- Build complete. Don't forget to run 'make test'. Installing shared extensions: /usr/local/php/php7/lib/php/extensions/no-debug-non-zts-20170718/
ls /usr/local/php/php7/lib/php/extensions/no-debug-non-zts-20170718/
以上已经编译安装完后。
配置 php.ini 配置文件
php -i
找到php的文件所在位置
vim php.ini 在末尾添加上
extension=mongodb.so
保存退出,重新启动php-fpm
我本地有一个phpfpm7的脚本,我使用以下命令进行启动:
service phpfpm7 restart
如果没有重新启动fpm的命令,可以使用
killall php-fpm
然后重新启动
/usr/local/php/php7/sbin/php-fpm