-
Notifications
You must be signed in to change notification settings - Fork 1.4k
-
Anybody knows why mongodb works fine in the console but returns 502 error code in the browser on mac?
Beta Was this translation helpful? Give feedback.
All reactions
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
-
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"
Beta Was this translation helpful? Give feedback.
All reactions
-
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 🫠
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks! I compiled the driver with OpenSSL. No longer getting 502 error. No trying to debug ssl certificate issues.
Beta Was this translation helpful? Give feedback.
All reactions
-
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
Beta Was this translation helpful? Give feedback.
All reactions
-
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:
- Can't connect to Atlas - Error:No suitable servers found mongo-php-library#313
- Connection fail due to ssl mongo-php-library#348
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.