← Back to Guides
Profile image for Adam Charvat
Published 20th January 2022

Deploying Strapi with PostgreSQL and Volumes

Strapi is an open-source headless CMS solution to create and manage your own APIs. Strapi is used to manage dynamic content with multiple contributors and can power your websites, blogs and applications.

In this guide, you will learn how to set up a new Strapi v4 deployment. Configuration data will be stored in a PostgreSQL database and media uploads will use persistent volumes.

Volumes are great for persisting data across service restarts. To learn more about them, read our changelog post.
If you prefer to upload media to your own S3 bucket read this guide instead.
  1. Create a new PostgreSQL database. For increased security, keep SSL enabled and External Access disabled. You can start with the smallest compute plan with 4 GB of storage and one replica.

    • Later, when you need to access the database in your local environment and run Strapi from your machine, you can use northflank forward in the Northflank CLI to forward the database for local development without enabling external access.
  2. Create a new secret group which will store the necessary environment variables.

    Manual Secrets

    KeyValue
    APP_KEYSString of two or more comma separated values
    JWT_SECRETString of 64 characters
    • Click on the key icon to use a built-in random key generator to generate long and secure strings.

    Inherited environment variables from the database

    Variable nameAlias
    HOSTDATABASE_HOST
    PORTDATABASE_PORT
    TLS_ENABLEDDATABASE_SSL
    DATABASEDATABASE_NAME
    USERNAMEDATABASE_USERNAME
    PASSWORDDATABASE_PASSWORD

    strapi-postgres-env-vars.png

    • Inheriting environment variables ensures that the database connection details are automatically injected in the environment, avoiding the need to manually copy and paste them.
    • To learn more about connection details inheritance, read our changelog post.
    • Save these variables in your local `.env` file to use when developing Strapi locally.
  3. Open our template repository and click Use this template to create a new repository in your account. Alternatively, install Strapi yourself following Strapi documentation and pushing to the version control system of your choice. Strapi will also use this repository to store some configuration of your dynamic content and plugins.

    • If you are installing Strapi make sure you select custom installation type and choose postgres from the list of available database clients. The below video shows how you can install Strapi in your terminal. You will likely need to run Strapi locally before deploying and you may need to include other environment variables such as APP_KEYS in your secret group. The values will get automatically generated when you first run Strapi in development. You must set the host to 0.0.0.0 before deploying on Northflank, rather than 127.0.0.1.
  4. Create a new combined service and select your repository as the source. Select Buildpack under build options and leave default heroku/buildpacks:20. Port 8080 will be automatically detected and exposed. You can start with the smallest resource plan nf-compute-10.

  5. Navigate to Volumes and add new volume. Choose the name, storage and set container mount path to /app/public/uploads. Saving the volume will rollout a restart and your Strapi deployment will be ready when the container boots up.

    • Volume storage cannot be scaled down once created. Start with the lowest one you need for your media uploads.

Once the container boots up, visit the service URL to create your first administrator account.

It may take a few minutes for Strapi to set everything up, view the container logs to see progress of the startup.

The below video will walk you through a custom Strapi v4 installation and set up on Northflank.

Using Northflank to deploy Strapi with PostgreSQL

Northflank allows you to deploy your code and databases within minutes. Sign up for a Northflank account and create a free project to get started.

  • Multiple read and write replicas
  • Observe & monitor with real-time metrics & logs
  • Low latency and high performance
  • Backup, restore and fork databases
  • Private and optional public load balancing as well as Northflank local proxy
Share this article with your network
X