How to install Strapi for Production on Ubuntu 20.04?

Overview

Strapi was built using JavaScript to create an open-source, headless Content Management System (CMS). Like other headless CMSs, Strapi is delivered without a front end. Instead, it uses an API that lets you design your own content architecture. Strapi also provides numerous ways to develop your website, integrating with well-known frameworks like React and Next.js. Additionally, you can use GraphQL or a REST API to consume an API.

We will be installing Strapi and setting up a production environment in this tutorial so that you can start producing content. In its development mode, Strapi uses SQLite, but you can set it up to utilize PostgreSQL instead.

Prerequisites

There are certain prerequisites that need to be met before you begin.

  • Ubuntu 20.04 LTS configured on your system with at least 2 CPU cores and 4GB ram as recommended by Strapi.

  • Non-root sudo user privileges.

  • Node.js version 16.xx or higher must be installed on your machine. Configure it using our Node.js Guide.

  • PostgreSQL must be installed on your machine. Configure it using our PostgreSQL Guide.

  • Nginx must be installed and configured as a reverse proxy. Configure it using our Nginx Guide.

Get Started

Step 1: Create a database using Postgres

Any project using Strapi needs a database. It currently supports PostgreSQL, MariaDB, MySQL, and SQLite. You cannot link an existing database to your Strapi installation instance because Strapi requires a new database. First, create a database and add a new user to it.

sudo -i -u postgres createdb strapi-db
sudo -i -u postgres createuser --interactive

Then, set a strong password for this PostgreSQL user which will allow Strapi to connect to your database. For doing so, go to the PostgreSQL terminal prompt.

sudo -u postgres psql

Now, update the user profile with a password of your choice and exit the prompt.

postgres=# ALTER USER test PASSWORD 'postgres_password';
postgres=# \q

Step 2: Strapi Installation on Your Machine

After the creation of your database and credentials, you can start installing Strapi on your machine.

npx create-strapi-app@latest my-project

Confirm your installation. Then, choose custom installation settings and fill in the following options.

You can begin building your Strapi project as soon as the installation is finished by changing your directory to "my-project" and executing the following command. With this command, your Strapi project will be created, along with the Strapi admin UI.

cd my-project
NODE_ENV=production npm run build

Your Strapi server is now ready for testing. To directly start your Strapi server, enter the following command.

node /home/ubuntu/my-project/node_modules/.bin/strapi start

Conclusion

You have successfully set up a production environment for Strapi using a PostgreSQL database. Additionally, you utilized an Nginx reverse proxy to deliver your Strapi application.

Last updated