Installing the PHP 7 MongoDB Client/Driver?

后端 未结 12 937
日久生厌
日久生厌 2020-11-28 06:17

I am very eager to start working with PHP 7 however one issue is getting in the way... I primarily use MongoDB for the database, and the problem is that I don\'t know how to

12条回答
  •  孤城傲影
    2020-11-28 06:48

    • First we need to install MongoDB in the machine through the steps mentioned here: https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
    • The next step is to install a MongoDB driver to use with PHP.
    • The MongoDB driver for PHP Version 5.99.99 or older was: https://pecl.php.net/package/mongo to install this we need to use:

      sudo apt-get install php-pear php5-dev

      sudo pecl install mongo

    • From PHP 7 onwards, this is the new driver https://pecl.php.net/package/mongodb To install that use: sudo pecl install mongodb

    • If you are using Laravel framework or projects with composer, then this library is the most apt one: https://github.com/jenssegers/Laravel-MongoDB Use version 3.0.0 to get PHP 7 & Laravel 5 support and otherwise use the older version 2.2.2 Composer command:

      composer require jenssegers/mongodb

    • If you are using other PHP frameworks without composer, use this library: https://github.com/mongodb/mongo-php-library which is also used in the above mentioned library

提交回复
热议问题