Learn to deploy Strapi on any Virtual Private Server: Host multiple Strapi Apps on a single VPS.


Strapi or Strapijs, has tremendously gained popularity among headless CMS over the years. There are many reasons for Strapi's growth, including but not limited to: being built primarily in JavaScript, the out-of-box REST API, its open-source nature, support for custom content types, and fields.
In this tutorial, my aim is to teach you about Strapi, and help you understand what Strapi is, what a Headless CMS is, what a VPS is, and what is needed to setup Strapi on any Virtual Private Server (VPS). I will also touch on the step-by-step process of setting up and automating a Strapi deployment on a VPS.

By the way, in the context of this tutorial, the term CMS stands for Content Management System.

Now, let's dive in!

What is Strapi?

Strapi is a headless CMS built in JavaScript (Node.js and React Library). It is open-source and among the most reliable headless CMSs used by solution-focused developers today.

Out of the box, it generates a REST API for your content, thus making your content accessible through versatile endpoints. You can customise the API to behave in any way you want to fit your unique needs. I refer to Strapi as a customisable low-code API builder. As of this writing, you can extend Strapi to support the GraphQL API by installing a GraphQL plugin. Click here to learn more about adding GraphQL support to Strapi.

What is a Headless CMS?

I describe a headless CMS as a platform whose frontend is meant for administrator users instead of normal users. Administrators can login to manage content, content types, fields, users, layouts, and perform customisations to meet their unique needs.

A headless CMS may come with an inbuilt API to expose it's content via endpoints so that it can be consumed on other platforms like web apps and mobile apps. Common headless CMSes you can compare with Strapi are Contentful and Sanity. Headless CMS are good for saving developers' time and costs. They also promote fast shipping of products by reducing the need for technical talent.

How to install Strapi

You need two environments to have a working instance of Strapi, which are the production and development environments.

The Production environment

To begin with, the production environment requires a public server on the internet. So, get a reliable VPS.

There are many reliable options out there. My go-to is Contabo, which is affordable and reliable. I have used it over the years for various setups, including setting up and offering reliable shared web hosting servers. Good options to look at are maybe Digital Ocean, Linode, Vultr, GCP, AWS, and many others; the options are nearly endless today.

For the specs, I recommend 4GB of RAM, 2 vCPUs, and 10GB+ storage.

Next, assign a public and static IP address to the VPS; this will come in handy when attaching domain names to your Strapi Headless CMS instances.

Next, you will have to install and configure the necessary tools to create a secure and functional production environment for node and static web apps.

In this post, I will not show the installation process but I will definitely publish that piece on my blog at https://blog.davidofug.com and YouTube https://youtube.com/@davidofug

That said, knowing the tools you need can help you get started right away, instead of waiting for my blog and YouTube tutorials.

So there are eight primary tools you need installed on your VPS.

1) Operating System: Ubuntu server 22.04 LTS

2) Version control: Ensure Git is installed

3) Runtime environment: Install Node.js 18.0.0

4) Web server: Install latest Nginx

5) Firewall: Install UFW

6) HTTP Security: Install Letsencrypt for generating FREE SSL

7) Node Process Manager: Install PM2 or Forever (I prefer PM2)

8) Database: Postgres or MySQL (I prefer Postgres)

That's it for the production environment.

The Developer environment

The development environment needs you to have a running version of Node.js 18.0.0 and Git

Then setup and deploy Strapi Headless CMS.

Development and Deployment steps

1. Download Strapi to your local machine. Then cd to the strapi project and execute npm install, followed by npm run develop.

2. Create a super admin account and login

3. Create Github repo for the project

4. Connect Github repo to the local Strapi repo

5. Create the collection types and add any fields you want

6. Commit changes and push to Github

7. SSH into my VPS

8. Add a domain name to the VPS

9. Map the domain name to the VPS

10. Create a server block for this domain

11. Create a Postgres database and credentials

12. cd to domain name directory

13. Pull from Github

14. Copy .env.example to .env and open the file for editing usually by runing sudo nano .env

15. Set values to the PORT, DATABASE_NAME, DATABASE_USERNAME, DATABASE_CLIENT and DATABASE_PASSWORD variables in the environment file. Additionally, generate the necessary tokens and secrets and set them too. Save your changes.

16. run npm install

17. run NODE_ENV=production npm run build; this will execute database migrations and build the static Strapi admin for you.

18. run pm2 start npm --name "my-app-name" --start

Note: Replace my-app-name with the appropriate name for your project.

19. Visit the domain in the browser.

20. Sign up for a super admin account in the production environment.

21. Login, and you will find all your content types and fields readily available from the local to the production environment. If there is some content you want to migrate from local to production, install the Export/Import plugin.

Now you can set APP API tokens that will be used to authorise the frontends.

Find the API at http://domain.com/api/{endpoint}

Auto Deployment

Have you deployed Strapi successfully? Now, you want to make changes on your local instance, and as you push on the Github repo, you want the changes to happen in your production. There are two ways I can suggest, 1) using github Actions or 2) using a bash script that is running a cronjob.


In this short post, we've looked at what strapi is and how to setup Strapi on any VPS. You can now build APIs without writing a line of code. Let me know if this helped you setup Strapi and if it didn't, give this post a thumbs up and share with your friends.

Do you want to learn about WordPress, Strapi, React, Linux and Technical writing? Consider to;-

Follow me @davidofug

Share this post

DM for one-on-one Mentorship

Hire me on Fiverr https://t.co/Yr5YfWQSad