This is the first article of the series Trying DigitalOcean App Platform which is part of DigitalOcean App Platform Hackathon
In this post, I will deploy a Strapi quickstart to DigitalOcean App Platform.
Update 2022: This post was created with Strapi version 3, the latest Strapi version is 4. There is an official video on Deploying Strapi V4 to DigitalOcean on YouTube.
Setup strapi
Create a strapi project in to my-project
directory.
npx create-strapi-app my-project --quickstart
The quickstart project will use a local sqlite as a database. The default sqlite database file is at ./.tmp/data.db
.
After the project has been created, the browser will be opened with admin setup page automatically. The admin user and content you create at this step will be available only on your computer since it is stored in local sqlite.
Production database config
To tell Strapi to use DigitalOcean database when we deploy it, create the following ./config/env/production/database.js
file.
module.exports = ({ env }) => ({
defaultConnection: "default",
connections: {
default: {
connector: "bookshelf",
settings: {
client: "postgres",
host: env("DATABASE_HOST", "localhost"),
port: env.int("DATABASE_PORT", 5432),
database: env("DATABASE_NAME", "strapi"),
username: env("DATABASE_USERNAME", "strapi"),
password: env("DATABASE_PASSWORD", "strapi"),
ssl: {
ca: env("DATABASE_CA", ""),
},
},
},
},
});
Develop Strapi
Develop Strapi as usual. If you are new to Strapi, you can try Quick Start Guide
Push code to GitHub repository
For example, here is my repository.
Launch DigitalOcean App
- Go to DigitalOcean App Platform Console and choose the repository.
- Choose the region that is close to your user
- Set the following environment variables and change HTTP port to
1337
. Notice thedb
prefix in environment variables.-
NODE_ENV
=production
-
DATABASE_HOST
=${db.HOSTNAME}
-
DATABASE_PORT
=${db.PORT}
-
DATABASE_NAME
=${db.DATABASE}
-
DATABASE_USERNAME
=${db.USERNAME}
-
DATABASE_PASSWORD
=${db.PASSWORD}
(Encrypt) -
DATABASE_CA
=${db.CA_CERT}
-
- Add database, set its name to
db
. The name must be the same as the prefix you used in environment variables. - Choose your plan and container size. The lowest cost plan is $12 (Basic $5/mo). Then launch your Strapi App! 🎉
Congratulations! 🎊
The Strapi application is being deployed and will be ready in around 10 minutes. You can visit https://<your-url>/admin
to setup production admin account.
Top comments (6)
Thanks for the resource. I also needed to
npm i pg strapi-provider-upload-do
and add this property to the config/database.js:if you only deploy Strapi to DO app platform thats fine, but if you attempt to deploy both Strapi and a static site (like Next Js for example) together you'll run into problems with http request routes. The way Strapi is configured was meant to be used with the default root route, but in most cases we want to point the static site to default route "/". So the workaround needed is to create 2 separate apps here, or avoid their app platform and create a droplet configuring everything manually. Hope this helps someone
The sintaxis of the database.js changed for Strapi v4, this is the new one:
Hello. I have a question about it. The Quick start created a SQLite dB and you use postgres. Are you sûre it will work fine? Because i followed tout tutorial and digital ocean cant deploy my app.
Yes. You have to make sure that you set
NODE_ENV
variable toproduction
and has./config/env/production/database.js
as I wrote above.can basic 5usd/mo plan work for strapi? mine is a practice project?