How to connect to MongoDB on App Platform - PHP

Posted September 19, 2021 114 views


Please I would like to know how could I install the extension and the library of MongoDB on App Platform with PHP.

I’ve tested this composer.json and it doesn’t work:

    "require": {
        "ext-mongodb": "*"

I’ve also tested “ext-mongo” instead of “ext-mongodb”. And also “ext-mongodb”: “^1.10.0”.

It displays me this error: “Build Error: Non-Zero Exit”.

The MongoDB database is on Digitalocean, and it’s linked to the app as a component.

Thank you!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

👋 @nawfal

I don’t think that error is related to the MongoDB. Build Error: Non-Zero Exit means that during build/detection the app errored, since PHP apps generally don’t compile, this is commonly caused by a missing composer.lock file.

Also, DigitalOcean MongoDB instances require connecting with a CA certificate. You can use bind variables to inject it by creating an environment variable like: CA_CERT=${db-mongodb-nyc1-12345.CA_CERT}.

Hope this helps!