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!
Strapi available on Coolify
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
Strapi app, and Postgres database deployed in Coolify
1. Deploy Postgres
First, install PostgreSQL from the resources to your project:
Install PostgreSQL
Set it up like this - give it a username, and database name, and update the password if you like.
For some raeson I have portmappings set to 5432:5432 - seems to work!
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:
Coolify - deploy a Git Based Application
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 postgres string has all the details for Strapi
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:
Successful Strapi deploy logs
Overall, this is going to save me $200 a month from Digital Ocean app platform!