I have installed mongodb on a newly installed Ubuntu 18.04 server, and while I am able to work with mongo on the command line, I cannot seem to connect to it using PHP.
I've been following the process as per https://www.youtube.com/watch?v=RQcQ5tvb5E8&t=620s:
apt install mongodb-server
apt install php-pear # to get PECL
apt install php7.2-dev # to get phpize
pecl install mongodb
phpinfo() shows extension_dir=/usr/lib/php/20170718, and mongodb.so is indeed in that directory, with the same ownership and permissions as all other files. php -i | grep extension_dir shows extension_dir => /usr/lib/php/20170718 => /usr/lib/php/20170718
I then added extension=mongodb.so to /etc/php/7.2/apache2/php.ini, in the same location as the other extensions are listed. There is also a php.ini file under /etc/php/7.2/cli/, so I added the line there to. I then restarted the apache2 service.
I created a test file under /var/www/html/mongo.php
<?php
$m = new Mongo();
var_dump($m);exit;
When I browse to that page I get a 'This page isnt working; HTTP ERROR 500' message in Chrome. I have also tried Mongodb();, MongoClient();, MongodbClient();, mongo();, mongodb();, and mongodbclient();, but all to no avail.
sudo systemctl status mongod
– Vikash Pathak