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
You can try install mongodb driver with:
sudo apt-get install php-mongodb
UBUNTU 16.0.4 (07.12.2016)
install PHP-MONGODB drivers :
Commandes :
- sudo pecl install mongodb
-> résultat :
Build process completed successfully
Installing '/usr/lib/php/20151012/mongodb.so'
install ok: channel://pecl.php.net/mongodb-1.2.0
configuration option "php_ini" is not set to php.ini location
You should add "extension=mongodb.so" to php.ini
-> la librairie se trouve dans "/usr/lib/php/20151012/mongodb.so"
- sudo systemctl restart apache2.service
https://secure.php.net/manual/en/mongodb.installation.pecl.php
- create 2 new files called "30-mongodb.ini" in both path to add the extension to your server:
-/etc/php/7.0/fpm/conf.d/30-mongodb.ini
-/etc/php/7.0/cli/conf.d/30-mongodb.ini
Commandes :
sudo nano /etc/php/7.0/fpm/conf.d/30-mongodb.ini
-> add "extension=mongodb.so"
sudo nano /etc/php/7.0/cli/conf.d/30-mongodb.ini
-> add "extension=mongodb.so"
- Test if the mongodb extension is running in your server :
Commandes :
php --ini
install DoctrineMongoDBBundle : http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html, http://www.doctrine-project.org/2016/06/09/odm-1-1-0-and-1-0-6.html,
Commandes :
- cd
- cd my_project_name
- ls -a composer*
-> résultat : composer.json composer.lock
- sudo nano composer.json
- Add to the composer.json in "require" array
"doctrine/mongodb-odm": "^1.0",
"doctrine/mongodb-odm-bundle": "^3.0"
- Add to the composer.json in "require" array
"alcaeus/mongo-php-adapter": "^1.0",
"ext-mongo": "*"
- Add a new array :
"provide":
{
"ext-mongo": "1.6.12"
}
- Move
sudo cp -i /usr/lib/php/20151012/mongodb.so /etc/php/7.0/cli
To give the solution I need at least 10 reputation to post...
The MongoDB driver that supports PHP 7 was only released December 22nd - its likely downstream repositories like brew haven't updated.
Update confirmed there is currently no php70-mongo
brew script, though there is an active pull request to add one.
You may be able to install it manually via pecl in the meantime:
pecl channel-update pecl.php.net
pecl install mongodb
echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
How to connect php 7.0 with MongoDB in ubuntu 16.04 lts?
1)Install LAMP using the following link. It installs Apache2, mysql and php 7.0. https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04
2)Install the MongoDB community Edition on Ubuntu using the steps in the following link. http://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
3)Type the following command to get the mongoDB extension from pecl
sudo apt install php-pear
4)Add the following to the php.ini file at /etc/php/apache2/7.0
extension=mongodb.so
Important - The classes have been changed too:
new MongoClient(); //Old Class
new MongoDB\Driver\Manager(); // New Class
Refer - http://php.net/manual/en/set.mongodb.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
I almost gave up, too. For The MongoDB driver for PHP 7x, Ubuntu 18.04 Pecl will not work. Instead, try:
sudo apt-get install php-mongodb
Then in the base of your project folder install the mongodb library https://docs.mongodb.com/php-library/current/tutorial/install-php-library/
composer require mongodb/mongodb
composer install
Which accesses the lower level functions provided by the driver.
Lastly, go to php.ini and add
extension = mongo.so
and restart apache
To test, try adding this to a php file:
<?php
require_once __DIR__ . "/vendor/autoload.php";
$collection = (new MongoDB\Client)->test->users;
print_r($collection);
?>