I. Environmental information

configuration information
PHP version PHP Version 7.4.4
Loaded Configuration File / usr/local/etc/PHP / 7.4 / PHP ini

Enough. The MAC is relatively simple and needs to know the path to php.ini.

Download the compressed package

The mongodb extension package is displayedDownload manager Unlike Windows, you need to click on the version.tazLink to download. For example, if my version is newer, let’s download it hereMongo - 1.9.1Version, we need to clickMongo - 1.9.1. TGZ (1255.8 kB)The corresponding link is carried outdownload.

Compile and install

  1. Decompress the download file. Decompress the download file to the /usr/local/ directory

  2. Go to the mongodb directory

    cdMongo - 1.5.5Copy the code
  3. Execute phpize to extend the PHP extension module

    phpize
    Copy the code

    The following output is generated

    AppledeMacBook - Pro: directing - 1.9.1 houxin $phpize youfor:
    PHP Api Version:         20190902
    Zend Module Api No:      20190902
    Zend Extension Api No:   320190902
    Copy the code

    If the message Cannot find config.m4. Is displayed, it indicates that the directory level is incorrect. Check whether there is another directory level nested under the current directory.

  4. Software compilation

    ./configure
    Copy the code

    The normal case would have the following output

    AppledeMacBook - Pro: directing - 1.9.1 houxin $. / configure checkingfor grep that handles long lines and -e... /usr/bin/grep
    checking for egrep... /usr/bin/grep -E
    checking for a sed that does not truncate output... /usr/bin/sed
    checking for pkg-config... /usr/local/bin/pkg-config
    checking pkg-config is at least version 0.9.0... yes
    checking for cc... cc
    
    ...
    
    config.status: creating /usr/local/ mongo - 1.9.1 / SRC/libmongoc/SRC/libmongoc/SRC/mongoc/mongoc - version. H config. Status: creating/usr /local/ mongo - 1.9.1 / SRC/libmongocrypt/SRC/mongocrypt - config. H config. Status: creating/usr /local/ mongo - 1.9.1 / SRC/libmongocrypt/SRC/mongocrypt. H config. Status: creating config. HCopy the code
  5. The installation

    make && make install
    Copy the code

    In the correct case, you will have the following output

    . Build complete. Don't forget to run 'make test'Installing Shared extensions: / usr/local/Cellar/PHP / 7.4.4 / pecl / 20190902 /Copy the code
  6. Verify that the extension was installed successfully

    mdfind -name mongodb.so
    Copy the code

    Examples are as follows:

    Appledemacbook-pro :mongodb-1.9.1 houxin$mdfind-name mongodb.so /usr/local/ mongo - 1.9.1 / modules/mongo. So/usr /local/lib/php/pecl/20190902/mongodb.so
    Copy the code

4. Modify the PHP configuration file

According to environmental information, PHP ini path is/usr/local/etc/PHP / 7.4 / PHP. Ini. Modify php.ini to add mongodb.so, just add mongodb.

extension=mongodb
Copy the code

5. Restart PHP

I’m using Valet locally, so my reboot is:

valet restart
Copy the code

Example:

Appledemacbook-pro :mongodb-1.9.1 houxin$valet restart Restarting DNsmasq Restarting php... Restarting nginx... Valet services have been restarted.Copy the code

Open phpInfo again and find that the mongodb extension has been loaded.