Reputation: 2713
I'm trying to install the MongoDB PHP driver so I can connect to a MongoDB Server on another machine. Using PHP 5.6 on AWS Linux.
I used sudo pecl install mongodb
. Initially there were several errors regarding dependencies but I added them all and it then seems to have installed without any errors.
However, when loading phpinfo()
I don't see any reference to Mongo. When I try to run:
$connection = new MongoClient();
I get
PHP Fatal error: Class 'MongoClient' not found in /var/www/html/mongo.php on line 3
I did put in extension=mongodb.so
into my php.ini but that results in another error:
PHP Startup: Unable to load dynamic library '/usr/lib64/php/5.6/modules/mongodb.so' - /usr/lib64/php/5.6/modules/mongodb.so: undefined symbol: php_json_serializable_ce in Unknown on line 0
It seems this error has to do with the order in which json loads relative to MongoDB. But as in my case it doesn't appear MongoDB is loading at all I'm not sure if that applies here.
I'd appreciate assistance as to why this isn't working.
Upvotes: 0
Views: 2024
Reputation: 67
For me, after following the sage advice above, I still couldn't see mongo in phpinfo. I finally resorted to uninstalling and reinstalling mongodb using pecl and noticed at the end of the output from make, it said:
configuration option "php_ini" is not set to php.ini location
Followed this: pecl config-set php_ini /etc/php.ini
Then:
sudo pecl uninstall mongodb
sudo pecl install mongodb
systemctl restart php-fpm
systemctl restart httpd
After that, mongo showed in both php -i:
php -i|grep mongo
/etc/php.d/50-mongodb.ini
mongodb
libmongoc bundled version => 1.9.4
libmongoc SSL => enabled
libmongoc SSL library => OpenSSL
libmongoc crypto => enabled
libmongoc crypto library => libcrypto
libmongoc crypto system profile => disabled
libmongoc SASL => disabled
libmongoc compression => enabled
libmongoc compression snappy => disabled
libmongoc compression zlib => enabled
mongodb.debug => no value => no value
And phpinfo:
http://1.2.3.4/phpinfo.php/
mongodb
MongoDB support enabled
MongoDB extension version 1.4.3
MongoDB extension stability stable
libbson bundled version 1.9.4
libmongoc bundled version 1.9.4
libmongoc SSL enabled
libmongoc SSL library OpenSSL
libmongoc crypto enabled
libmongoc crypto library libcrypto
libmongoc crypto system profile disabled
libmongoc SASL disabled
libmongoc compression enabled
libmongoc compression snappy disabled
libmongoc compression zlib enabled
Directive Local Value Master Value
mongodb.debug no value no value
Upvotes: 1
Reputation: 2215
I had faced the same situation and i got this solution from mongo developers You don't need to put mongodb.so in php.ini instead make it a separate module If you are using debian
cat << EOF > /etc/php5/mods-available/mongodb.ini
; priority=99
extension=mongodb.so
EOF
php5enmod mongodb
if you are using fedora
echo "extension=mongodb.so" > /etc/php.d/50-mongodb.ini
Then restart your apache And it will work fine.
Upvotes: 0
Reputation: 53
Long story short, use of MongoClient for PHP is deprecated. ( https://github.com/mongodb/mongo-php-driver/issues/300#issuecomment-210820288 )
Instead of $connection = new MongoClient();
You'll want to use
$connection = new MongoDB\Driver\Manager();
Hope this helps.
Upvotes: 0