Strapi Installation: Production Environment on Ubuntu 22.04
What Will You Learn in This Guide?
In this guide, you will learn how to implement Strapi CMS into a production environment on Ubuntu 22.04.
PostgreSQL, PM2, Nginx reverse proxy and Let's Encrypt SSL configuration is covered.
What is Strapi?
Strapi is a JavaScript-based, open source headless CMS solution.
It does not contain a frontend, it serves content via API.
Provides REST and GraphQL support.
It is compatible with frameworks such as React and Next.js.
Prerequisites
The following should be ready before continuing:
- Ubuntu 22.04 server
- Node.js v16.x
- PostgreSQL installed and running
- Nginx reverse proxy configured
- Domain name redirected to server IP
Recommended hardware: 2 CPU + 4 GB RAM
1. Creating a PostgreSQL Database
Strapi requires an empty database.
sudo -i -u postgres createdb strapi_db
- This command creates a new PostgreSQL database.
Create user:
sudo -i -u postgres createuser sammy
- This command adds a database user.
Define password:
sudo -u postgres psql
ALTER USER sammy PASSWORD 'guclu_sifre';
\q
- This process allows Strapi to connect to the database.
2. Strapi Setup
- Install Strapi with npx:
npx create-strapi-app@latest my-project
- This command starts the Strapi installation wizard.
- During installation, make these selections:
-Custom installation
1. JavaScript
2. PostgreSQL
3. Enter your database information
4. SSL: No
- After installation, enter the project:
cd my-project
- Get production build:
NODE_ENV=production npm run build
- This command compiles the Strapi admin panel for production.
3. Running Strapi as a Service with PM2
- PM2 allows Strapi to run in the background.
Install PM2:
sudo npm install pm2@latest -g
- This command installs the PM2 process manager.
Create configuration file:
nano ecosystem.config.js
module.exports = {
apps: [
{
name: "strapi",
cwd: "/home/sammy/my-project",
script: "npm",
args: "start",
env: {
NODE_ENV: "production",
DATABASE_HOST: "localhost",
DATABASE_PORT: "5432",
DATABASE_NAME: "strapi_db",
DATABASE_USERNAME: "sammy",
DATABASE_PASSWORD: "guclu_sifre",
},
},
],
};
- This structure allows PM2 to run Strapi in production mode.
Start:
pm2 start ecosystem.config.js
- To start automatically at server startup:
pm2 startup
pm2 save
- These steps ensure service permanence.
4. HTTPS with Nginx and Let's Encrypt
- Strapi runs HTTP by default.
- Let's Encrypt is used for HTTPS.
Install Certbot:
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
- This command installs the SSL management tool.
Firewall settings:
sudo ufw allow 'Nginx Full'
sudo ufw delete allow 'Nginx HTTP'
- This process only allows HTTPS traffic.
Get an SSL certificate:
sudo certbot --nginx -d ornek-domain.com -d www.ornek-domain.com
- This command retrieves the certificate and applies it to Nginx.
Access to Strapi Admin Panel
- The admin panel can be accessed at:
https://ornek-domain.com/admin
-
An administrator account is created at the first login.
-
Content management is started via the panel.
Frequently Asked Questions (FAQ)
1. Why does Strapi require Node.js 16? Newer versions are incompatible with some plugins.
2. Why PostgreSQL instead of SQLite? It is more reliable and scalable for the production environment.
3. Does it work without PM2? It works, but Strapi stops when the service shuts down.
4. Is HTTPS mandatory? Highly recommended for production environment.
Result
With this guide, you have made Strapi ready for the production environment. A secure CMS infrastructure was established with PostgreSQL, PM2, Nginx and SSL.
For more stable and scalable Strapi projects, you can try the GenixNode infrastructure immediately.

