

In today's digital landscape, the ability to host your applications independently can be a game changer. In this guide, we will explore how to set up a Payload NextJS project with a MongoDB database using Coolify. The process not only allows you to run production workloads affordably but also ensures you remain fully GDPR compliant. Whether you're a developer looking to streamline your database management or simply curious about the capabilities of Payload and MongoDB, this article will provide you with all the insights you need.
This article provides a detailed written step-by-step tutorial based on our comprehensive video guide available on YouTube at https://www.youtube.com/watch?v=OOFIMV5Up3A. If you're a visual learner or prefer following along with video instruction, the accompanying video covers the same content while offering additional context and real-time demonstrations of each step in the process. Whether you prefer reading or watching, both resources will guide you through deploying Payload with MongoDB on Coolify for independent, cost-effective hosting.
When it comes to managing databases, many developers rely on third-party services like MongoDB Atlas for ease of use and convenience. However, there are several compelling reasons to consider self-hosting your database. First and foremost, self-hosting can reduce dependency on external services, giving you greater control over your data. This independence is crucial for various reasons:
Now that we've established the importance of self-hosting, let’s dive into the practical steps of setting up a Payload project with MongoDB on Coolify. First, ensure you have a GitHub repository ready for your project.
Follow these steps to create your Payload project:
npx create payload app@beta to initialize your Payload application. This command will set up the latest beta version of Payload.Once the setup is complete, you can verify that your local Payload project is running correctly.
Before we create our database in Coolify, let’s configure it for optimal performance. One feature to take advantage of is the wildcard domain. This allows you to automatically create DNS records for your projects. Here’s how to set it up:
*.projects.allaboutpayload.com.This configuration ensures that whenever you deploy a new project, it will automatically be assigned a unique subdomain under your wildcard domain.
With Coolify configured, it's time to create your MongoDB database:
After starting the database, you can check its status. If everything is running smoothly, you should see the MongoDB service operational.

At this point, the database is only accessible internally. If you want to make it publicly available, you'll need to select a public port (e.g., 5432) and check the box to make it publicly accessible. This will generate a public MongoDB URL that can be used to connect from external servers.
To test the connection, update your environment variables with the new remote URL. Start your development server using:
npm run dev
Once the server is running, navigate to localhost:3000/admin to access the admin panel where you can create your first user.
To manage your MongoDB database visually, you can use MongoDB Compass. For this, replace the local connection string with the remote URL in Compass. Keep in mind that you may receive a warning indicating that TLS/SSL is disabled, meaning the traffic between your server and the database is not encrypted. While this is a drawback compared to using MongoDB Atlas, it’s manageable for development purposes.
With your project and database ready, it’s time to deploy your Payload application on Coolify. Follow these steps:
After setting up the GitHub app, you can link your Payload project with the repository.
Before finalizing the deployment, adjust the health check settings. The default path may return a 404 error, so ensure you set the health check path to /admin.
Lastly, add your environment variables. Since you can access the database using the local URL, paste it in the relevant environment variable field to enhance security. This way, you can restrict public access to the database while still allowing connections from your application.
After saving all configurations, initiate the deployment. It might take a few minutes, but once completed, you will have a fully operational Payload project with MongoDB hosted on Coolify.

Once the deployment is complete, you can access your application via the automatically generated subdomain under your wildcard domain. If you navigate to the admin panel, you should be able to log in and manage your application seamlessly.
Setting up a Payload NextJS project with MongoDB on Coolify is not only straightforward but also offers numerous benefits, including cost efficiency, data control, and enhanced GDPR compliance. By following the steps outlined in this guide, you can successfully self-host your applications while maintaining full control over your data.
If you have any questions or need further assistance, feel free to reach out in the comments section below or check out our resources at AllAboutPayload.
Payload CMS is a headless content management system that allows developers to build flexible and scalable applications using modern technologies.
MongoDB offers a NoSQL structure, which allows for more flexibility in data storage and schema management, reducing the risk of data loss during schema changes.
Coolify offers competitive pricing, allowing you to run production workloads for as little as €7 per month, depending on your server configuration.
Self-hosting offers greater control over your data, and by using private internal URLs, you can enhance security by restricting public access to your database.
Yes, with Coolify, you can manage multiple projects and scale your resources as needed without significant overhead.