This tutorial looks into how to install latest MongoDB with PHP on Fedora.
Create a /etc/yum.repos.d/mongodb.repo file:
vi /etc/yum.repos.d/mongodb.repoIf you are running a 64-bit system, use the following configuration:
[mongodb] name=MongoDB Repository baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/ gpgcheck=0 enabled=1else for 32-bit system, use:
[mongodb] name=MongoDB Repository baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686/ gpgcheck=0 enabled=1To install the latest stable version of MongoDB, issue the following command:
yum install -y mongodb-orgInstall php,mongo driver:
pecl install mongocreate a mongo (php) ini
vi /etc/php.d/mongo.iniAnd include the driver:
extension=mongo.soEnable mongod on startup
systemctl enable mongodstart mongod:
service mongod startOpen mongo client to test.
mongocreate database test:
use testLets do an insert:
db.collection1.insert({"name":"desc"})And lets do an query:
db.collection1.find();Lets proceed with using mongodb in php. Restart php-fpm:
systemctl restart php-fpm.serviceWe shell create a php script:
<?php $connection = new Mongo(); $dbname = $connection->selectDB('test'); $collection = $dbname->collection1; $arr = array( 'name' => 'MongoDB', 'desc' => 'MongoDB is a document database.' ); $collection->insert($arr); $result = $collection->find(); foreach ($result as $document) { echo $document["name"]."\n"; echo $document["desc"]."\n"; } ?>You can run above script in web server or just run:
php test_mongo.php