如何在PHP 7中为Mongodb连接启用libmongoc ssl?
问题描述:
While connecting to mongodb via PHP7, I am getting following error:
The "SCRAM-SHA-1" authentication mechanism requires libmongoc built with --enable-ssl
This is probably due to libmongoc SSL disabled in php7:
MongoDB support => enabled
MongoDB extension version => 1.4.4
MongoDB extension stability => stable
libbson bundled version => 1.9.4
libmongoc bundled version => 1.9.4
libmongoc SSL => disabled
libmongoc crypto => disabled
libmongoc SASL => disabled
libmongoc compression => enabled
libmongoc compression snappy => disabled
libmongoc compression zlib => enabled
How can I enable it?
答
To resolve this error in PHP7 execute following command as super user:
- Install required dependencies:
yum install git php-devel make gcc openssl-devel
- Clone, compile and build Mongo PHP Driver from source:
git clone https://github.com/mongodb/mongo-php-driver.git
cd mongo-php-driver/
git submodule update --init
phpize
./configure --with-php-config=/usr/bin/php-config --with-mongodb-ssl=openssl
make
cp ./modules/mongodb.so /usr/lib64/php/modules/
- Add mongodb.so to php.ini if not already there.
"extension=mongodb.so"
- Restart the webserver to reflect the changes:
systemctl restart httpd.service
答
@doumei7420 大佬的回答解决了我的问题,非常感谢!