CentOS Install PHP 7 's MongoDB extension encounters the Pit
When I deploy a PHP environment on Docker, the installation of MongoDB extensions encounters a pit:
PHP Fatal error:uncaught mongodb\driver\exception\authenticationexception:the "scram-sha-1" authentication mechanism Requires LIBMONGOC built With–enable-ssl
This error should only appear on MongoDB that is set up to require login verification.
I didn't think much at first, after I found the extension of MongoDB on pecl, I compiled it directly:
phpize./configuremakemake install
After simply writing the test code, the following error occurred:
PHP Fatal error:uncaught mongodb\driver\exception\authenticationexception:the "scram-sha-1" authentication mechanism Requires LIBMONGOC built With–enable-ssl in/var/www/html/mongo.php:8\nstack trace:\n#0/var/www/html/mongo.php (8): Mongodb\driver\manager->executebulkwrite (' Test.tb ', Object (mongodb\driver\bulkwrite)) \n#1 {main}\n thrown in/ Var/www/html/mongo.php on line 8
At first the suspicion is that ./configure
you need to add some option parameters, to ./configure --help
find the relevant similar to the above error in the above --enable-ssl
options, Target Lock:
However, even after this option is added: It ./configure --with-mongodb-ssl
is still useless to recompile.
Baidu a circle can not find a solution, on Google a bit, sure enough to find the key to the problem:
The problem is on the disabled in the red box on the phpinfo's MongoDB extension information.
The basic reason is that I used the Docker image is too clean, even OpenSSL did not, so first installed on OpenSSL:
yum install -y openssl openssl-devel
Recompile the MongoDB extension ( ./configure
No need to add the above option parameter, because the default value is --with-mongodb-ssl=auto
), and then go to Phpinfo to see:
Really different, and then run the test code, test success!
Record the pit of PHP7-MONGODB expansion once