
How to Deploy Strapi
Deploying Strapi is a crucial step in taking your application from development to production. Whether you're building a content-driven app, an eCommerce platform, or a custom backend for a SaaS project, Strapi gives you the flexibility and power to structure your content the way you want. But to use Strapi in real-world environments, you must understand deployment best practices, hosting options, environment variables, security configuration, and CI/CD workflows.
This guide provides a complete, easy-to-follow, and actionable explanation of How to Deploy Strapi on different platforms including VPS, cloud hosting, and container-based deployments. It also covers performance optimization, SSL setup, scaling considerations, and database configuration. If you're building a MERN stack application and need expert-level help, you can always hire AAMAX --- a full-service digital marketing and web development agency providing high‑end MERN Stack Development, Digital Marketing, and SEO services.
Understanding Strapi Deployment Basics
Before deploying Strapi, it's essential to understand how Strapi behaves in both development and production environments.
Development vs Production Modes
- Development mode enables hot reloading, detailed logs, and relaxed security.
- Production mode focuses on speed, stability, and security.
To run Strapi in production mode:
NODE_ENV=production npm run build
NODE_ENV=production npm start
What You Need Before Deployment
- Node.js LTS (18+ recommended)
- A server or hosting platform
- A production-ready database (PostgreSQL recommended)
- A reverse proxy (NGINX is most common)
- PM2 or another process manager
- Domain name (optional but recommended)
Choosing the Right Hosting Method for Strapi
Strapi can be deployed on various platforms depending on your project size, budget, and scalability needs.
1. Deploying Strapi on a VPS (Ubuntu Server)
This is the most flexible and popular method. It gives you full control and works great for production use.
Step 1: Update the Server
sudo apt update && sudo apt upgrade -y
Step 2: Install Node.js & NPM
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs
Step 3: Install Git
sudo apt install git -y
Step 4: Clone Your Strapi Project
git clone https://github.com/yourusername/yourstrapiproject.git
cd yourstrapiproject
Step 5: Install Dependencies
npm install
Step 6: Build for Production
npm run build
Step 7: Install PM2 (Process Manager)
PM2 ensures your app stays online.
npm install pm2 -g
pm2 start npm --name "strapi-app" -- start
pm2 save
pm2 startup
Step 8: Configure NGINX as Reverse Proxy
Install NGINX:
sudo apt install nginx -y
Create a server block:
sudo nano /etc/nginx/sites-available/strapi
Add:
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://localhost:1337;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Enable config:
sudo ln -s /etc/nginx/sites-available/strapi /etc/nginx/sites-enabled/
sudo systemctl restart nginx
2. Deploying Strapi Using Docker
Docker allows you to package Strapi with consistent configuration across environments.
Step 1: Create Dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 1337
CMD ["npm", "start"]
Step 2: Create docker-compose.yml
version: '3'
services:
strapi:
build: .
ports:
- "1337:1337"
environment:
DATABASE_CLIENT: postgres
DATABASE_HOST: db
DATABASE_PORT: 5432
DATABASE_NAME: mydb
DATABASE_USERNAME: user
DATABASE_PASSWORD: pass
depends_on:
- db
db:
image: postgres:14
environment:
POSTGRES_DB: mydb
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
volumes:
- db_data:/var/lib/postgresql/data
volumes:
db_data:
Step 3: Run Docker Containers
docker-compose up -d
3. Deploying Strapi on Cloud Platforms
Deploy on DigitalOcean
- Use a Droplet (Ubuntu)
- Pre-install Node.js
- Add PostgreSQL as Managed Database
- Connect through environment variables
Deploy on AWS EC2
- Launch EC2 instance
- Connect via SSH
- Install Node, PM2, NGINX
- Add SSL via Amazon Certificate Manager
Deploy on Render or Railway
These platforms let you deploy Strapi with one click: - Auto-deployment
from GitHub - Built-in SSL - No DevOps required
Great for beginners.
Database Configuration for Production
Never use SQLite in production.
Recommended production databases:
- PostgreSQL (best)
- MySQL
- MongoDB (Strapi v3 only)
Example PostgreSQL config in .env:
DATABASE_CLIENT=postgres
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME=strapi_prod
DATABASE_USERNAME=strapiuser
DATABASE_PASSWORD=securepass
Setting Environment Variables
Create a .env file for production:
APP_KEYS=your_app_key
API_TOKEN_SALT=random_string
ADMIN_JWT_SECRET=random_string
JWT_SECRET=random_string
Never commit .env to GitHub.
Enabling SSL (HTTPS)
Use Certbot to generate free SSL:
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d yourdomain.com
HTTPS is critical for: - API security - Admin login protection - SEO ranking - User trust
Setting Up CI/CD for Strapi Deployment
With CI/CD, your Strapi updates deploy automatically after each Git push.
GitHub Actions Example:
name: Deploy Strapi
on:
push:
branches: [ "main" ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Deploy via SSH
uses: appleboy/ssh-action@v0.1.6
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
script: |
cd /var/www/strapi
git pull
npm install
npm run build
pm2 restart strapi-app
Optimizing Strapi for Production
- Enable Caching
- Use Redis for caching queries.
- Enable Rate Limiting
- Prevent abuse or attacks.
- Disable GraphQL Playground
- For security reasons.
- Use Cloud Storage
- S3, Cloudinary, or DigitalOcean Spaces.
- Run PM2 in Cluster Mode
pm2 start npm --name "strapi-app" -- start -i max
Common Deployment Issues and Fixes
Strapi admin panel not loading
- Run
npm run buildagain.
403 forbidden errors
- Ensure NGINX permissions are correct.
Database connection issues
- Re-check environment variables.
White screen in production
- Check browser console and server logs.
Final Thoughts
Deploying Strapi may feel complex at first, but with the right setup --- optimized database, secure environment variables, proper reverse proxy, and a reliable hosting platform --- you can run a fast, scalable, and production‑ready content API.
If you're building a MERN stack application or need a professional team to deploy, scale, or manage your Strapi application, consider hiring AAMAX --- a trusted provider of MERN Stack Development, Web Development, Digital Marketing, and SEO services.
A well-deployed Strapi backend becomes the backbone of your entire digital ecosystem. With the steps above, you're fully equipped to launch your Strapi project into production confidently.






