Strapi QuickStart on DigitalOcean App Platform
Tags: dohackathon, strapi
Published: 2021-01-04 15:32:38

This is the first article of the series **Trying DigitalOcean App Platform** which is part of [DigitalOcean App Platform Hackathon](https://dev.to/devteam/announcing-the-digitalocean-app-platform-hackathon-on-dev-2i1k)

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](https://youtu.be/tnGqqUzzh6U).

## Setup strapi
Create a strapi project in to `my-project` directory.
```sh
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.

![Admin setup page](https://dev-to-uploads.s3.amazonaws.com/i/9ty22jkifb4cccs576tf.png) 

## Production database config
To tell Strapi to use DigitalOcean database when we deploy it, create the following `./config/env/production/database.js` file.

```js
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](https://strapi.io/documentation/developer-docs/latest/getting-started/quick-start.html)

## Push code to GitHub repository

For example, here is [my repository](https://github.com/ThewBear/do-strapi).

## Launch DigitalOcean App

1. Go to [DigitalOcean App Platform Console](https://cloud.digitalocean.com/apps/new) and choose the repository. ![Choose the repository](https://dev-to-uploads.s3.amazonaws.com/i/vbs4xv36cy24lwe3cmkn.png)
2. Choose the region that is close to your user ![Choose region](https://dev-to-uploads.s3.amazonaws.com/i/u8bhqu5fz4n17r9x5ykh.png)
3. Set the following environment variables and change HTTP port to `1337`. Notice the `db` 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}`![Set enivronment variables and HTTP port](https://dev-to-uploads.s3.amazonaws.com/i/70klm0rwqezmbtx5esdr.png)
4. Add database, set its name to `db`. The name must be the same as the prefix you used in environment variables.![Add database](https://dev-to-uploads.s3.amazonaws.com/i/t9ofq7u5qkwp75r9hjja.png)
5. Choose your plan and container size. The lowest cost plan is $12 (Basic $5/mo). Then launch your Strapi App! 🎉 ![Choose pricing plan](https://dev-to-uploads.s3.amazonaws.com/i/hefnrdtfjsq7gppo0tqr.png)

## 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.

<a href="https://www.buymeacoffee.com/thew" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-blue.png" alt="Buy Me A Coffee"></a>