You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

  1. Restart Apache to apply changes:
    service httpd restart
    
  2. Check your phpinfo() output — look for the mongodb section, and confirm that libmongoc SSL support shows as enabled.
  3. Test your Laravel MongoDB connection again — the SCRAM-SHA-1 error should now be resolved.

内容的提问来源于stack exchange,提问作者Nagaraj Jayaraman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:59:29