Question

How to connect to MongoDB on App Platform - PHP

Hi,

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:

code
{
    "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!


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

👋 @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!