Laravel5.4连接MongoDB3.6报错:需启用SSL的libmongoc
Yep, you’re spot on — the error you’re seeing is directly caused by libmongoc having SSL support disabled. MongoDB 3.6’s SCRAM-SHA-1 authentication mechanism requires the underlying libmongoc library to be compiled with SSL enabled, which your AWS Linux environment is missing. Your Ubuntu 16.04 setup works because the official packages for libmongoc there include SSL support by default.
Here’s how to fix this by recompiling libmongoc with SSL enabled, then reinstalling the php-mongodb extension to link against it:
Step 1: Clean up existing installations
First, remove the current php-mongodb extension and any pre-built libmongoc packages to avoid conflicts:
# Uninstall the php-mongodb extension via pecl pecl uninstall mongodb # If you installed libmongoc via yum, remove those packages too yum remove -y libmongoc libmongoc-devel
Step 2: Install build dependencies
You’ll need SSL development libraries and build tools to compile libmongoc properly:
yum install -y openssl-devel gcc make php70-devel php-pear
(Note: If you’re using Amazon Linux 2, adjust package names as needed — e.g., php70-devel might become php-devel if you’ve enabled the appropriate PHP repo.)
Step 3: Compile libmongoc with SSL support
We’ll use a version of libmongoc compatible with MongoDB 3.6 (1.13.x branch):
# Create a temp directory for source files mkdir -p /tmp/mongoc && cd /tmp/mongoc # Download the source tarball for libmongoc 1.13.1 (from the official MongoDB C Driver releases page) # Extract and enter the source directory tar -zxf mongo-c-driver-1.13.1.tar.gz && cd mongo-c-driver-1.13.1 # Configure the build with SSL enabled (using OpenSSL) ./configure --enable-ssl=openssl # Compile and install make && make install # Update system library cache so the new libmongoc is detected ldconfig
Step 4: Reinstall the php-mongodb extension
Now install the php-mongodb extension that’s compatible with Laravel 5.4 (version 1.5.5), ensuring it links to our newly compiled libmongoc:
pecl install mongodb-1.5.5
During the installation, if prompted about enabling SSL support, select yes.
Step 5: Verify the fix
- Restart Apache to apply changes:
service httpd restart - Check your
phpinfo()output — look for themongodbsection, and confirm thatlibmongoc SSL supportshows asenabled. - Test your Laravel MongoDB connection again — the SCRAM-SHA-1 error should now be resolved.
内容的提问来源于stack exchange,提问作者Nagaraj Jayaraman

