Running Strapi with PM2 on a VM: when it fits
PM2 is a Node.js process manager that supervises the Strapi process on a single host, and it fits teams that run Strapi on one Linux virtual machine and need the application to restart after a crash and come back after a reboot. It does not replace anything Strapi itself provides. Strapi's documentation covers how the application is built, configured and started, including the production build, the environment settings and the database connection. PM2 adds the layer that watches the running process, restarts it when it exits unexpectedly, writes its output to log files, and brings it back up when the machine restarts. If your deployment has one host, one database and no need to balance traffic across several instances, that division of responsibility is usually enough.
The fit depends on the versions you can run. Strapi 5 runs only on Active or Maintenance LTS Node.js versions, so check the current Node.js release schedule before you pick the runtime on the VM. The database must be PostgreSQL 14 or later, MySQL 8.0 or later, MariaDB 10.3 or later or SQLite 3, and MongoDB is not supported. Confirm the exact requirements against the Strapi installation requirements for the version you are deploying, because the supported list changes with releases. If your team has to move to a different database engine to meet a policy, settle that before you write the ecosystem file, since the process manager setup will not change the database layer.
Ask whether PM2 is the right boundary before you commit to it. A single VM means a single point of failure: PM2 can restart Strapi after a crash, but it cannot keep the service up if the host, its disk or its network fails. If you need several Strapi instances behind a load balancer, or you already run containers or Kubernetes, a process manager on a VM is the wrong layer and the sibling topics on containers and orchestration apply instead. If the answer is a single host with a clear recovery plan, such as restoring the database and the uploads directory to a second VM, PM2 is a reasonable choice. Write that recovery plan down alongside the process configuration, because the process manager will not be the part that fails when the VM is lost.
Which process model fits which deployment
A single virtual machine running one Strapi instance is the situation PM2 is designed for in this topic. PM2 starts the Node.js process from an ecosystem file, keeps it running after crashes, manages logs and can be registered to start on reboot. The main decision is whether PM2 alone is enough or whether the host's init system should own the process instead.
- Process supervision: PM2 restarts a crashed Strapi process and holds the process list in its own daemon, so you manage it with the
pm2command. - Boot behavior: PM2 generates a startup script for the init system on the host. Confirm which init system your distribution uses and what the generated unit does.
- Log handling: PM2 writes stdout and stderr to files you name in the ecosystem file, which makes rotation a separate task to plan.
- Operator skill: Teams that already run services with systemd may prefer a unit file, with PM2 optional.
- Scope limit: A single VM has no built-in second instance, so a host failure stops the service until the VM recovers.
Before you commit, confirm with your platform team which init system and log collector the host already uses, and whether one instance meets your availability needs.
When you run more than one Strapi instance behind a load balancer, each instance needs the same configuration and the process manager must start and stop each one without taking the whole pool down. PM2 can run several processes of the same app, but the balancer, health checks and shared resources such as uploads and sessions decide whether this works. The process model is only one part of the design.
- Instance count: PM2 runs multiple copies of one app on a host, while a balancer spreads traffic across hosts or ports.
- Health checks: The balancer should check a health endpoint before routing traffic. Confirm the health path your Strapi version exposes.
- Shared state: Uploads, database settings and any session or cache store must be shared or externalized across instances.
- Rolling restarts: Restart instances one at a time so the balancer keeps at least one healthy target.
- Configuration drift: Each host needs the same ecosystem file, environment values and build output.
Confirm your balancer's health-check and drain behavior in its own documentation before planning restarts, because the rolling pattern depends on it.
In a containerized estate, the image and the container runtime already define how the application starts, restarts and writes logs. A PM2 process inside a container adds a second supervisor under the container's main process, which changes how signals and restarts are handled. Many teams therefore keep PM2 on bare VMs and let the container runtime own the process in containers. Other teams keep PM2 inside an image for consistency, and that choice needs testing.
- Two supervisors: A PM2 daemon inside a container can hide crashes from the runtime unless the container is set to fail when PM2 exits.
- Signal handling: Confirm that shutdown signals reach the Node.js process so Strapi can close connections cleanly.
- Restart policy: The runtime's restart policy and PM2's restart behavior should not fight each other.
- Logging: Container logs usually go to the runtime's log driver, so PM2 file logs may be redundant.
- Image rebuilds: Config changes need a new image rather than an in-place PM2 reload.
Test a PM2-in-container build against your runtime's signal and restart behavior before you adopt it as a standard.
Kubernetes takes over scheduling, health probing, rolling updates and scaling across nodes. PM2 has no role in this model because the cluster controller starts and restarts containers, so the ecosystem file is not used. The questions move to probe configuration, secret handling, database connectivity and how schema changes roll out across replicas. The detailed Kubernetes steps belong to a separate deployment topic.
- Replacement of PM2: The cluster controller restarts failed pods, so PM2 is not needed for supervision.
- Probes: Liveness and readiness probes replace PM2's crash-restart loop and decide when traffic reaches a pod.
- Configuration: Environment values come from config maps and secrets rather than a host-level ecosystem file.
- Rollouts: Schema changes and database migrations must run once per release, not once per replica.
- Platform dependency: Cluster operation requires skills and tooling your team must already have or plan to acquire.
Ask your platform team which orchestrator, ingress and secret store they operate, because those choices decide how much of this model applies to Strapi.
PM2 configuration options and when each fits
This table compares the ecosystem file keys you will set for a Strapi process and shows when each one fits. Read it as a checklist: the first column names the key, the second says what it controls for Strapi, and the third says when to change it from the default. Keys marked as version dependent should be checked against the PM2 release you install.
| Key | What it controls for Strapi | When to set it |
|---|---|---|
name | The process name PM2 uses in pm2 list, logs and restart commands | Always set it, so scripts and runbooks refer to one stable name such as strapi-api |
script | The entry point PM2 starts, usually the Strapi start command through npm or the built server file | Set it to the same command you verify by hand, and confirm the start path matches your build output |
cwd | The project directory, which must contain the built dist output, .env and package.json | Set it on every VM deployment so the process does not start from the wrong folder after a reboot |
instances and exec_mode | How many copies run and whether PM2 balances them in cluster mode | Use one instance with fork unless you have confirmed that every instance can share uploads, sessions and scheduled tasks |
env and env_production | Environment variables such as NODE_ENV, database settings and server URL, applied on start or with --env production | Keep secrets out of the file; load them from the host or a protected .env and confirm how your PM2 version applies env_production |
max_memory_restart | Restarts the process when resident memory passes a set limit | Set it as a safety net for slow leaks, sized above normal peak use on your VM; tune it from observed memory, not a guess |
out_file and error_file | Paths where stdout and stderr are written, separate from PM2's own log | Point both to a directory the service user can write to and rotate them with a log tool |
autorestart and restart_delay | Whether PM2 restarts a crashed process and how long it waits between attempts | Leave autorestart on for production; add a delay if a bad configuration would otherwise restart in a tight loop |
kill_timeout | Milliseconds PM2 waits after a stop signal before forcing exit, giving Strapi time to close database connections | Raise it if in-flight requests or migrations need longer to finish; confirm the default for your PM2 version |
Setting up the Strapi ecosystem file and startup
This sequence takes a Strapi project from a production build to a PM2-managed process that starts on boot and answers health requests. Each step ends with a check, so the team knows the process is supervised correctly before anyone depends on it.
Install a supported Node.js LTS and build Strapi
The platform engineer installs a Node.js version that is on Strapi's supported list, which is limited to Active or Maintenance LTS releases, and confirms it with the node and npm version commands on the VM. Then they run the production build from the project directory so the admin panel is compiled ahead of time. Confirm the Node.js version against the current Strapi installation requirements before choosing it. The step is done when the build completes without errors and the dist output exists in the project.
Write the PM2 ecosystem file
The engineer creates an ecosystem file, usually named ecosystem.config.js, that defines the app name, the start script that launches Strapi in production mode, the working directory, the instance count and the restart and memory limits. Keep the file in version control, but keep secrets out of it. The check is a dry read: running pm2 ecosystem with the file path should parse it without a syntax error and list the expected app name.
Set production environment variables
The engineer sets NODE_ENV to production and provides the database connection values, the APP_KEYS, API_TOKEN_SALT, ADMIN_JWT_SECRET and JWT_SECRET values, and the public server URL through the environment, either in the ecosystem file's env block or in a file that the host loads securely. Secrets should come from a secret store or a restricted file with tight permissions, not from a shared repository. The check is that Strapi reads the values at startup, which the logs in the next steps will confirm.
Start the process under PM2
The engineer starts the app with pm2 start pointing at the ecosystem file, then confirms that PM2 shows the process as online. If Strapi exits during startup, PM2 will report repeated restarts, which usually points to a missing variable or a database that cannot be reached. The check is a status line showing the process online with a stable restart count after a short wait.
Save the process list
The engineer runs pm2 save so PM2 writes the current process list to its dump file. This file is what PM2 uses to restore the app after a restart of the PM2 daemon. Save only after the app is working correctly, because the saved list will be restored on every boot. The check is that the dump file is updated and that pm2 list shows the same app name and status.
Generate and run the startup hook
The engineer runs pm2 startup, which prints a command for the host's init system, typically systemd on most Linux VMs. They run that printed command with the privileges it requires, then confirm the unit is enabled. Run the command as the account that owns the Strapi files, and check the printed user in the output. The check is that the init system reports the PM2 unit as enabled, which can be verified with the init system's status command.
Verify status, logs and a health request
The engineer reads pm2 status and pm2 logs for the app to confirm there are no startup errors or repeated restarts. They then request the health endpoint on the configured port from the VM and from the path users will use, and they open the admin panel in a browser. The check is a successful health response, an admin login page that loads, and clean logs. If the health route is disabled or unavailable in the project, confirm the alternative check with the team that owns the Strapi configuration.
Prove the process survives a reboot
In a planned test window, the engineer reboots the VM and waits for the host to return. After boot, they confirm that PM2 restored the Strapi process without manual action, then repeat the status, log and health checks. Record the result in the change record, including the Node.js version, PM2 version and the date. The sequence is complete only when the restored process passes the same checks as before the reboot.
How zero-downtime restarts work with Strapi schema changes
A PM2 reload keeps the process list available while new Node.js processes start, but it does nothing to the database. Strapi 5 runs data migration scripts on first start, so the first boot of a new build can change stored data before any request is served. Treat every release that touches content types, components or the database layer as a change that needs a plan, even when the reload itself looks invisible. The Strapi upgrade docs say to back up the database before upgrading and note that downgrading is not supported, so a rollback after a migration means restoring from backup, not redeploying the previous build. Confirm the exact migration behavior for your target version in the Strapi v4 to v5 migration docs before you schedule the change.
A rolling PM2 reload across several instances is generally safe when the release makes no schema or data changes and the instances share one database. Even then, check that every instance can start against the current schema, because a migration that runs on the first instance can affect the others while they are still serving traffic. When the release includes a migration, the safer pattern is to stop writes, run the upgrade on one controlled instance, verify the admin panel and key API routes, and only then bring the rest online. If editors must not lose work during that window, plan a short maintenance window and communicate it. The length of that window depends on your data volume and migration runtime, so measure it on a staging copy rather than assuming it.
Run the full sequence on a staging copy of production data before the production change. Restore a recent backup into a separate database, point a staging PM2 process at it, perform the reload and migration exactly as the runbook describes, and record how long the first start takes, what changed in the schema and whether the admin panel and content API behave as expected. Include a restore test in the same run so you know the backup is usable. Use the results to decide whether production needs a maintenance window, and write the go or no-go criteria into the change ticket before the window opens.
Security and operational risks of a PM2 host
A PM2 host is one VM running one or more Node.js processes, so its risks sit in a small number of places: the user the process runs as, the files and shell history that hold secrets, the logs it writes, the Node.js runtime it depends on, the single machine it lives on, and the admin panel it may expose. Each card below names one of these risks and the check that confirms it is handled.
Process running as root
If Strapi starts under root, any code execution bug in the application, a dependency or a plugin gives an attacker root on the VM. Run PM2 and the Strapi process as a dedicated system user with no login shell, own the project directory with that user, and keep write access limited to the upload directory and any local files Strapi must write. Confirm with ps -o user= -p <pid> that the process user is not root, and confirm that PM2 was started by that user so its saved process list reflects it.
Secrets in the ecosystem file
The ecosystem file often holds APP_KEYS, JWT_SECRET, ADMIN_JWT_SECRET, API_TOKEN_SALT and database passwords in plain text, and those values can end up in version control or in ~/.bash_history when they are typed on the command line. Keep the ecosystem file free of secret values and load them from a root-owned environment file with mode 600 or from a secrets manager. Check the repository history for committed values and rotate any secret that has appeared in a commit or shell history.
Logs that capture sensitive data
PM2 writes stdout and stderr to files under ~/.pm2/logs, and Strapi error output can include request bodies, query parameters, tokens or database errors that echo user data. Those files are often readable by more people than the application data is. Restrict the log directory to the service user, set a log rotation policy with pm2-logrotate, and review sample log lines after a test run to confirm that tokens and personal data are not printed. Ask your security team what retention applies to these logs.
Unpatched Node.js runtime
Strapi 5 runs only on Active or Maintenance LTS Node.js versions, so a runtime that falls out of support also stops being a supported Strapi runtime. PM2 does not update Node.js on its own, and a host image built months earlier can keep an older version in place. Record the installed Node.js version in your runbook, check it against the Strapi installation requirements before each upgrade window, and schedule runtime patches alongside OS patches.
Strapi installation requirementsSingle VM as a single point of failure
PM2 restarts a crashed process, but it cannot recover a failed VM, a corrupted disk or an unreachable zone. Every Strapi instance, the local upload directory and the process manager state live on one machine, so one hardware or hypervisor fault stops the service. Decide the recovery target in advance: keep a tested image or configuration that rebuilds the host, store uploads in external object storage, use a managed or separate database, and document how long a rebuild takes in your own environment.
Admin panel exposed to the internet
The Strapi admin panel is a web interface for administrator accounts, and on a PM2 host it is often served on the same public address as the API. Limit access to the admin path at the reverse proxy by IP range or VPN, keep server.url and the admin URL correct so login redirects work, and enable SSO for administrators where your identity provider supports it. Confirm from an outside network that the admin path is unreachable when it should be closed.
Questions buyers ask about running Strapi with PM2
What does running Strapi with PM2 cost, and who pays for what?
The software itself is a cost you can avoid: Strapi's Community Edition is free under the MIT Expat license, and PM2 is open source. The money goes to people and infrastructure. You pay for the VM or cloud instance, the managed or self-run PostgreSQL, TLS certificates, backups and the engineering hours to configure, harden and document the setup. If you use the self-hosted Growth or Enterprise plans, the license fee is an additional recurring cost, and SSO sits in the Growth add-on or in Enterprise. Ask any partner for a quote built from a written scope that lists each of these items separately, so you can see which costs are one-time and which recur.
How long does setup and hardening take, and what drives that?
Duration depends mainly on how many environments you run, how much of the surrounding stack is new to your team, and how strict your review process is. A single production VM with an existing database and reverse proxy is a much smaller job than a setup that must also cover staging, log shipping, a restart policy tested after reboot, and a documented rollback. Other drivers include the Strapi version you start from, custom plugins that need native builds, and whether your security team requires evidence of each control. Ask for a schedule tied to named milestones in the written scope rather than a single total.
What must our team provide before the work starts?
Plan to supply the following before the first working session:
- SSH or configuration-management access to the VM, with a named account and sudo rights for service setup
- A PostgreSQL 14 or later, MySQL 8.0 or later, or MariaDB 10.3 or later database that the VM can reach, with credentials
- DNS records and a TLS certificate or the means to issue one
- A secrets store or approved method for
.envvalues such asAPP_KEYS,JWT_SECRETand database passwords - Node.js versions approved by your platform team, limited to Active or Maintenance LTS releases
- Named owners for backups, log retention and change approval
Confirm each item with your own environment before the scope is signed.
Can an internal team set up Strapi with PM2 alone?
Yes, if at least one engineer is comfortable with Linux service management, Node.js builds, reverse proxies and database operations, and if the team has time to test restarts and rollbacks. The work is not exotic, but mistakes often appear later: a process that does not start after reboot, environment variables missing in one instance, logs that fill a disk, or a deployment that interrupts users. Teams that want an outside review often ask for a partner to build the first setup, document it and hand over a runbook, then run the routine upgrades in-house. Decide based on who will carry the pager after go-live.
When is PM2 the wrong choice for Strapi?
PM2 fits a small number of Node.js processes on virtual machines that you manage directly. It is the wrong choice when you need scheduled rollouts across many hosts, automatic scaling, or a platform that already runs containers or Kubernetes. In those cases, a container image with health probes on the /_health endpoint and a managed rollout is usually easier to audit and recover. PM2 is also a weak fit if your security team requires an orchestrator's built-in policy controls. Compare the operational model with your existing platform before choosing it. See also the Strapi installation requirements for the Node.js and database versions Strapi supports.
What recurring work follows go-live, including Node.js and Strapi upgrades?
Recurring work includes watching Node.js release status and moving to a version that is still Active or Maintenance LTS, because Strapi 5 runs only on those. Strapi 5 minor releases have shipped roughly weekly, so set a cadence for reviewing them, test each one in staging and schedule production changes. Strapi v4 reached end of life on April 30, 2026, so any remaining v4 instance needs a planned migration. Other recurring tasks are database backups and restore tests, PM2 and operating system patches, certificate renewal, log rotation review and access reviews for the VM. Ask for these as a retainer or runbook in the written scope.
How PM2, Strapi and the reverse proxy fit on one VM
A client request enters the VM at the reverse proxy, which terminates TLS and forwards traffic to the Strapi process that PM2 keeps running. Strapi reads and writes the database and stores uploads on local or mounted storage. On reboot, a systemd startup hook restarts PM2, which restarts Strapi. Strapi and PM2 write logs to files that operators must rotate and review. Check that the proxy headers, database connection and upload path all sit inside the trust boundary you intend.
Request path, startup hook, storage and logs on a single Strapi VM.
What changes once Strapi runs under a process manager
Once PM2 supervises Strapi, a release stops being a file copy and becomes a build, copy and reload sequence, and each step has its own failure mode. The build runs npm run build to compile the admin panel and TypeScript output, the copy puts the new build in the release directory, and the reload tells PM2 to restart the Node process without dropping connections. Teams should decide who owns each step, whether the build happens on the target VM or on a CI runner, and what the rollback is if the reload starts the new code but Strapi fails its first boot. Schema changes add a separate question: Strapi 5 runs database migrations on start, so the reload is also the moment production data changes, and that needs a backup and a rehearsal before the first production reload.
Logs also move. Strapi writes to standard output, and PM2 captures that stream into files under its log directory, usually one file for output and one for errors per application. Nobody needs to attach a terminal to read the process any more, but they do need to know where the files are, how they rotate, and who can read them, since application logs can include request details. Ask the team that owns the VM to confirm the log path, the rotation policy and the retention period before go-live, and check whether a log shipper will read these files or whether logging goes to a separate service. Those answers belong in the runbook, not in someone's memory.
On-call staff need a short set of commands that show state without changing it. pm2 status lists each process with its restart count, uptime and memory, which is usually the first place to see a crash loop. pm2 logs tails output and errors, and pm2 describe shows the environment and script path PM2 actually launched, which settles arguments about which build is running. The restart count matters most: a count that rises after each deploy points to a boot failure, a missing environment variable or a database connection problem. Write these commands, the expected output and the escalation path into the runbook so an engineer who did not perform the deploy can diagnose a fault at night.

