Strapi
Pm2 Ecosystem for Ubuntu Vps

pm2 ecosystem for Ubuntu VPS in production.

I use this in production for my personal projects

As my config and preference for the file and folder:

  • /home/deploy/ecosystem.config.js (File)
  • /home/deploy/strapi-backend/ (Folder)

In terminal at the file level type:

pm2 start ecosystem.config.js

Once apps is an array you can insert more apps in the list and all will run when you type the command

When using Strapi 4 just replace with your API_KEYS, SECRET, TOKEN, etc as you need.

/home/deploy/ecosystem.config.js
module.exports = {
  apps: [
    {
      name: "strapi-backend",
      cwd: "./strapi-backend",
      script: "server.js", // I file I keep at the root of strapi - check /strapi/server.js
      instances: 'max', // Max processors available in the VPS
      exec_mode: 'cluster',
      watch: ["config", "src", "package.json", "tsconfig.json", "types"], // Watching all folders stuck restarting forever, so I ellected these files
      env: {
        NODE_ENV: "production",
        HOST: "0.0.0.0", // Can be this host in production
        PORT: 1337, // Common port used for strapi can be 1338 or other
        APP_KEYS: "MsAhzB+gfjuZKLl/Xvnewt==,2UcDZflGRo+LINUrLoZ/2w==,GRMvm0IJcoYmB+q5Vs1xew==,4F5bnd0onvED1F6H570Zcg==", // Must change
        API_TOKEN_SALT: "lsvXtXIFGR57HSAPM3lC5w==", // Must change
        ADMIN_JWT_SECRET: "Ht3ifQS7irSbOFpYmeaAJQ==", // Must change
        TRANSFER_TOKEN_SALT: "BZA0EGVJyx6t/fBhOH8ycQ==", // Must change
        // Database
        DATABASE_CLIENT: "sqlite", //If you are using sqlite keep it
        DATABASE_FILENAME: ".tmp/data.db", //If you are using sqlite keep it
        JWT_SECRET: "KVO7sOUwx9TcnHbGWquPjw==", // Must change
        // Your API
        OPENAI_API_KEY: "sk-zeGAbhtvLMMu2T4FlbkFJwOz4eYd20QOBGvQRCAf5UHm4knY", // Must change
        SENDGRID_API_KEY: "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", // Must change
      }
    },
  // You can add more apps in this array
  ],
};

Check Strpi server.js file

Last updated on