You can deploy Strapi on Coolify in 1 click from the projects dashboard – that's great for new projects, but what if you have an existing Strapi project in GitHub you want to deploy? This post will show you how!
Deploy as 2 Resources: Postgres + Strapi
If you're deploying from GitHub, we deploy 2 things separately, and use them together:
A Postges database for the data
Your Strapi repository
Letter
1. Deploy Postgres
First, install PostgreSQL from the resources to your project:
Set it up like this - give it a username, and database name, and update the password if you like.
You can set the public port to 5432, and check make it publicly available if you're connecting from outside your server. Press deploy.
2. Deploy GitHub repo
Once that's running, it's time to deploy your Strapi GitHub repo. Choose public or private respository, whatever is your repo:
Then to configure it, use this stuff:
Set the Build: npm install, Build Command: npm run build --production, Start Command: npm run start
Then set Ports Exposes as 1337, and 1337:1337
Connect Strapi to Postgres
Finally, to connect Strapi to your Postgres DB, you need to add the DB Name, DB Host, DB Username, DB Password, and DB Port to your Environmental Variables of the Strapi app.
This is the bit that tripped me up. If you're deploying your Strapi application on the same server as the database, just use the values that are shown in the internal connection string. Head back to your database config page, and you'll see this in the following field as Postgres URL (internal):
The hostname for internal will just be a random word. Whereas if you're connecting from outside, check the publicly available box, and follow the external string that will show up.
That should be it, you can check the logs to see if it connects:
Overall, this is going to save me $200 a month from Digital Ocean app platform!