Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Installation Issue With PHP MongoDB Extension on MacOS #2627

Closed Answered by alcaeus
frknasir asked this question in Q&A
Discussion options

Anybody knows why mongodb works fine in the console but returns 502 error code in the browser on mac?

You must be logged in to vote

This sounds like an issue that was reported a couple of weeks ago: mongodb/mongo-php-library#1145 (comment)

TL;DR: php was compiled with OpenSSL, the extension with Secure Transport. The linked issue explains how you can compile the driver with OpenSSL instead to avoid the segmentation faults. The upcoming 1.17 release (currently scheduled for early November) will change the default library to OpenSSL on MacOS and only fall back to Secure Transport if OpenSSL could not be found.

Replies: 3 comments 4 replies

Comment options

Usually, it's due to the extension not enabled in php-fpm.

  • Restart php-fpm
  • Check phpinfo() in a webpage
  • Ensure the extension is enabled in php.ini of your php-fpm
$ cat /opt/homebrew/etc/php/8.2/conf.d/ext-mongodb.ini
extension="mongodb.so"
You must be logged in to vote
1 reply
Comment options

So checking phpinfo(), I see that it is enabled. I use laravel herd. I thought it was a herd issue but it doesn't work as well when I run PHP artisan serve...

in the php-fpm log I see something about "upstream crashing or closing after X seconds....".

It works in the console but it doesn't work in tinker mode.

It's been one and a half weeks already trying to debug it 🫠

Comment options

This sounds like an issue that was reported a couple of weeks ago: mongodb/mongo-php-library#1145 (comment)

TL;DR: php was compiled with OpenSSL, the extension with Secure Transport. The linked issue explains how you can compile the driver with OpenSSL instead to avoid the segmentation faults. The upcoming 1.17 release (currently scheduled for early November) will change the default library to OpenSSL on MacOS and only fall back to Secure Transport if OpenSSL could not be found.

You must be logged in to vote
1 reply
Comment options

Thanks! I compiled the driver with OpenSSL. No longer getting 502 error. No trying to debug ssl certificate issues.

Answer selected by jmikola
Comment options

I am here now. it works with php artisan serve but not when I use Laravel herd. Mongodb seems to expect me to indicate where a copy of a valid certificate is. If true, any idea how I can accomplish that? Thanks.

No suitable servers found (`serverSelectionTryOnce` set): [TLS handshake failed: certificate verify failed (20): unable to get local issuer certificate calling hello on 'ac-cgob3rg-shard-00-00.hfcdrin.mongodb.net:27017'] [TLS handshake failed: certificate verify failed (20): unable to get local issuer certificate calling hello on 'ac-cgob3rg-shard-00-01.hfcdrin.mongodb.net:27017'] [TLS handshake failed: certificate verify failed (20): unable to get local issuer certificate calling hello on 'ac-cgob
You must be logged in to vote
2 replies
Comment options

I am here now. it works with php artisan serve but not when I use Laravel herd.

I don't believe you acknowledged @alcaeus's previous response in #2627 (comment) about manually compiling the 1.17-dev (master branch) of the extension to test the recent fix in PHPC-2280, which changed the default TLS library on macOS to OpenSSL from Secure Transport.

The server selection error you shared suggests a problem with the CA file in the Laravel Herd environment. Some older issues that might be helpful to diagnose this further are:

Also, there is a connect.php tool in the PHPLIB repository that may also be useful. It attempts to connect to a MongoDB cluster directly using PHP socket functions (without the driver), and will also attempt to validate the cert using PHP's openssl extension. The FAQ: Server Selection Failures article in the PHPLIB documentation talks a bit more about it.

Note that even after the Secure Transport to OpenSSL change in PHPC-2280, it's possible that PHP's openssl extension in Laravel Herd is configured with different certificates than the OpenSSL system library -- that has come up before in older driver/library issues on GitHub, such as those referenced above. If that is the case, the connect.php tool should help clarify as much since it uses the openssl extension for verification.

Comment options

I don't believe you acknowledged @alcaeus's previous response in #2627 (comment) about manually compiling the 1.17-dev (master branch) of the extension to test the recent fix in PHPC-2280, which changed the default TLS library on macOS to OpenSSL from Secure Transport.

Apologies. I just did now. Did the compilation manually. no longer getting 502 errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /