Strapi QuickStart on DigitalOcean App Platform
Thew
Posted on January 4, 2021
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.
Posted on January 4, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.