SoFunction
Updated on 2025-03-10

Analysis of the method of installing mongoDB extension for php7

This article describes how to install mongoDB extensions in php7. Share it for your reference, as follows:

Here we use the pecl command to install it

First, come to the installation directory of php7

$ /usr/local/php7/bin/pecl install mongodb

Enter, after successful execution, the following results will be output:

……
Build process completed successfully
Installing '/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/'
install ok: channel:///mongodb-1.1.7
configuration option "php_ini" is not set to  location
You should add "extension=" to 

Next we need to open the file and add extension=config

Or directly execute the following command to add:

Copy the codeThe code is as follows:
$ echo "extension=" >> `/usr/local/php7/bin/php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`

After configuring, the above is successful. Execute phpinfo(). If you see mongoDB, then congratulations. The installation is successful. If you don’t see it, please consciously check your development environment.

Note: The installation directory of php7 in the above command is /usr/local/php7/. If you install it in another directory, you need to modify the paths of pecl and php commands accordingly.

For more information about PHP related content, please check out the topic of this site:Complete collection of PHP+MongoDB database operation skills》、《Summary of PHP's skills to operate database based on pdo》、《PHP object-oriented programming tutorial》、《Summary of usage of php strings》、《PHP+mysql database operation tutorial"and"Summary of common database operation techniques for php

I hope this article will be helpful to everyone's PHP programming.