How to Self Host Strapi

How to Self Host Strapi

How to Self Host Strapi

Self‑hosting Strapi gives you full control over your backend, database, API security, and infrastructure costs. Whether you're building a small business website or a large‑scale enterprise application, hosting Strapi on your own server can give you more customization options, flexibility, and better performance tailored exactly to your needs.

This in‑depth guide (1500+ words) walks you through everything you need to know about how to self host Strapi---including server setup, environment configuration, deployment, database integration, and optimization tips.

If you ever need expert help, you can hire AAMAX for MERN Stack Development services. AAMAX is a full‑service digital marketing company offering Web Development, Digital Marketing, and SEO services.

## Why Choose to Self Host Strapi?

Self‑hosting Strapi provides benefits such as:

  • Full Control Over Server Environment: Install only the tools you need.
  • Better Security Management: Control firewall, SSL, access logs, and server‑level security.
  • Scalability Options: Scale your application using containers, load balancers, and cloud servers.
  • Cost Savings: Avoid recurring SaaS hosting fees.
  • Performance Optimization: Tune Node.js, database, and caching layers for top speed.

Self hosting is ideal for developers and businesses who want maximum flexibility or need to integrate Strapi into an existing infrastructure.

## Prerequisites for Self Hosting Strapi

Before you self host Strapi, ensure you have the following:

### Server or Hosting Environment

Any of the following is suitable:

  • A VPS (DigitalOcean, Vultr, Linode)
  • A dedicated server
  • A cloud VM (AWS EC2, Google Cloud Compute Engine, Azure VM)
  • A local machine for testing (not recommended for production)

Recommended minimum production specs:

  • 2 CPU cores
  • 4 GB RAM
  • 40 GB SSD storage
  • Linux-based OS (Ubuntu 20+ recommended)

### Installed Software

You'll need these:

  • Node.js (v18 or newer)
  • npm or yarn
  • Git
  • Reverse proxy (Nginx or Apache)
  • Database system such as:
    • PostgreSQL (recommended)
    • MySQL
    • MariaDB
    • MongoDB (not officially recommended for Strapi v4+)
    • SQLite (only for development)
  • Firewall configuration (UFW recommended)

## Step 1: Prepare Your Server

Start with updating your server packages:

sudo apt update && sudo apt upgrade -y

Install build tools:

sudo apt install build-essential gcc g++ make -y

Install Git:

sudo apt install git -y

## Step 2: Install Node.js (Recommended LTS Version)

Use the NodeSource installation script:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs

Verify installation:

node -v
npm -v

## Step 3: Create a New Strapi Project

Navigate to your home directory or project directory:

cd /var/www

Create a new Strapi project:

npx create-strapi-app my-strapi-app --quickstart

If you want to use a custom database, omit --quickstart:

npx create-strapi-app my-strapi-app

Move into the project:

cd my-strapi-app

## Step 4: Configure Environment Variables

Create an .env file:

touch .env
nano .env

Add essential variables:

HOST=0.0.0.0
PORT=1337
APP_KEYS=somesecretkey1,somesecretkey2
API_TOKEN_SALT=randomsalt
ADMIN_JWT_SECRET=adminjwtsecret
TRANSFER_TOKEN_SALT=transfersecret

Add database configuration based on your DB choice.

## Step 5: Install and Configure a Database

PostgreSQL is recommended for production.

### Install PostgreSQL

sudo apt install postgresql postgresql-contrib -y

Create a user and database:

sudo -u postgres psql
CREATE USER strapi WITH PASSWORD 'password';
CREATE DATABASE strapidb OWNER strapi;
\q

### Update Strapi Database Configuration

Edit database file at:

./config/database.js

Example config:

module.exports = ({ env }) => ({
  connection: {
    client: 'postgres',
    connection: {
      host: env('DATABASE_HOST', '127.0.0.1'),
      port: env.int('DATABASE_PORT', 5432),
      database: env('DATABASE_NAME', 'strapidb'),
      user: env('DATABASE_USERNAME', 'strapi'),
      password: env('DATABASE_PASSWORD', 'password'),
      ssl: false,
    },
  },
});

## Step 6: Build the Admin Panel

In production, you MUST build the admin panel manually:

npm run build

## Step 7: Run Strapi in Production Mode

Start the production server:

npm run start

To keep Strapi running after closing the terminal, use PM2.

### Install PM2

npm install pm2 -g

### Start Strapi with PM2

pm2 start npm --name "strapi" -- run start

Enable automatic start:

pm2 startup
pm2 save

## Step 8: Configure NGINX as a Reverse Proxy

Install NGINX:

sudo apt install nginx -y

Create a new config:

sudo nano /etc/nginx/sites-available/strapi

Add:

server {
  server_name yourdomain.com;

  location / {
    proxy_pass http://127.0.0.1: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 the config:

sudo ln -s /etc/nginx/sites-available/strapi /etc/nginx/sites-enabled/
sudo systemctl restart nginx

## Step 9: Secure Your Strapi Installation

### Enable Firewall

sudo ufw allow 'Nginx Full'
sudo ufw allow ssh
sudo ufw enable

### Enable HTTPS with SSL (Let's Encrypt)

Install Certbot:

sudo apt install certbot python3-certbot-nginx -y

Run SSL setup:

sudo certbot --nginx -d yourdomain.com

## Step 10: Optimize Strapi for Production

### Increase Node.js Memory Limits

In your PM2 file or startup command:

node --max-old-space-size=2048

### Use a CDN for Media

Strapi supports:

  • AWS S3
  • Cloudinary
  • Google Cloud Storage
  • Azure Blob Storage

Install Cloudinary provider:

npm install @strapi/provider-upload-cloudinary

### Enable Caching Layers

Use Redis for caching:

sudo apt install redis-server

## Step 11: Set Up Backups

### Backup Database Automatically

Example PostgreSQL backup:

pg_dump strapidb > backup.sql

Schedule a cron job for automatic backups.

### Backup Uploads Folder

rsync -av ./public/uploads /backup/location

## Step 12: Common Issues and Fixes

### Strapi Admin Panel Not Loading

Run:

npm run build

### Database Connection Errors

  • Check DB credentials
  • Ensure PostgreSQL is running:
    sudo systemctl status postgresql

### Port Already in Use

sudo lsof -i :1337
sudo kill -9 <PID>

### NGINX Not Redirecting Properly

Verify:

sudo nginx -t

## Best Practices for Self Hosting Strapi

  • Always use HTTPS
  • Never store JWT secrets in code
  • Enable production logging
  • Keep Node.js updated
  • Use a monitoring system (Prometheus, Grafana)
  • Never give public access to /admin without protection

## Final Thoughts

Self‑hosting Strapi is a powerful option for developers and businesses that want complete flexibility over their API and content management system. By setting up your own server environment, you gain better control over performance, security, scalability, and cost efficiency.

Whether you're deploying Strapi for a personal project or a full‑scale enterprise platform, following the step‑by‑step instructions in this guide will help you launch a stable, secure, and high‑performance self‑hosted Strapi server.

If you need expert help with MERN Stack Development or Strapi customization, you can always hire AAMAX for professional support and enterprise‑grade development solutions.

Related Blogs

Top Citation Sites for Cleaners

Top Citation Sites for Cleaners

Explore the ultimate list of citation sites for cleaners. Improve local SEO, gain trust, and increase leads with powerful directories designed for cle...

How to Run Strapi Project

How to Run Strapi Project

Strapi is one of the best tools for modern backend development. Whether you're building a full‑stack MERN application or a headless CMS for content‑dr...

Top Citation Sites for Locksmiths

Top Citation Sites for Locksmiths

Find the best locksmith citation sites to strengthen rankings, build credibility, and grow your locksmith business through high-quality listings and e...

How to Run Strapi in Development Mode

How to Run Strapi in Development Mode

Running Strapi in development mode is a straightforward yet essential process for building powerful APIs and modern applications. From hot‑reloading t...

How to Self Host Strapi

How to Self Host Strapi

Whether you're deploying Strapi for a personal project or a full‑scale enterprise platform, following the step‑by‑step instructions in this guide will...

How to Start Strapi

How to Start Strapi

Starting Strapi is easier than ever. With its flexible architecture, rich plugin ecosystem, and strong developer‑friendly design, Strapi empowers you ...

Need Help? Chat with Our AI Support Bot