MongoDB on Laravel Homestead with PHP 7

Hi, folks!
Because I had some troubles with installing and enabling MongoDB driver on Laravel Homestead with PHP 7 version installed on it, I will explain here how I have solved them.

Install MongoDB package

Import public key:

 sudo apt-key adv --keyserver hkp:// --recv 7F0CEB10 

Creating a List File:

 echo "deb "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list 

Update packages list:

 sudo apt-get update 

Install MongoDB package:

sudo apt-get install -y mongodb-org

Make connection with PHP

Firstly, I have installed PHP MongoDB driver:

sudo pecl install mongodb

Secondly, I have added in


and in


the following code 

Finally, we need to save the changes:

sudo service php7.0-fpm restart && sudo service nginx restart
Silviu Stroe
I'm Silviu and I run Brainic, a mobile-focused software agency. I'm also a member of Nokia and Yahoo wall of fame. My interests are in low-code/no-code development and bleeding-edge technologies.

2 thoughts on “MongoDB on Laravel Homestead with PHP 7”

Leave a Reply

Your email address will not be published. Required fields are marked *