There are multiple cloud options to deploying your Strapi app, but, in this article, I will walk you through how to install your Strapi instance on a Virtual Private Server for usage.
The article will be focused on introducing you to setting up an existing Strapi App and deploying on a VPS.
Strapi is an open-source headless Content Management System that offers you the chance to develop API with distinctive features. It's built on Node.js and works with any GraphQL enabled Frontend Frameworks.
You are able to create custom content types, relationships and media library for images and audio files with Strapi.
A Virtual Private Server is a multi-tenant infrastructure as a service cloud-hosting provided for developers to host their website and application by hosting platform.
At the end of this guide, you should be able to set up a VPS, install your core requirements, and clone and deploy your Strapi project on VPS.
Before you continue with this content, you require the following.
We will be using Lightsail VPS for this tutorial.
If you see “pending” instead of “running”, just wait a couple minutes.
In this phase, we'll work on setting up our project:
git version
The command above will show you the current version of git and if it turns an error you will have to install git.
git clone (url)
# mine is:
git clone https://github.com/ibn-ashimi/my-project.git
Now, we have our project on the VPS, we will proceed to setting it up.
yarn -v
#or
npm -v
This will show you the version you have installed. In my case, my yarn is version 1.22.18 and my npm is version 8.5.5, which is okay.
You need to install the npm packages to deploy project. You could use either Forever JS or PM2.
cd (project name)
npm install --production
#and
npm i forever -g
#or
npm i pm2 -g
It is advisable to install both forever and pm2. If you experience npm permissions issues, use Sudo.
Now, we need to configure our app and install dotenv which will contain our environment variables.
npm i dotenv
cp .env.example .env
Open .env
1 nano .env
and include the variables from your database
1 HOST=0.0.0.0
2 PORT=1337
3 APP_KEYS=2V+39791mGaxSwRHHhwfhg==,aMWCRV6iaTxRZXx5NM/2BA==,rIsvFirfdm8YNwsy0QnLug==,dWUY3urnIol5YOkpdLTkfQ==
4 API_TOKEN_SALT=ksJpczGexS/3UaQ4Lb2efQ==
5 ADMIN_JWT_SECRET=S1WqtEgbW9ZKy3eF2JUbZQ==
6 JWT_SECRET=S72rrbkK0kCk1eE6g5CqIA==
To do this, run:
1 NODE_ENV=production yarn build
2 #or
3 NODE_ENV=production npm run build
You should receive a success prompt.
To have your app deployed with forever or PM2, create a “server.js” file using
1 nano server.js
and input
1 const strapi = require('@strapi/strapi');
2 strapi(/* {...} */).start();
then save.
1 NODE_ENV=production pm2 start server.js --name api
2 # or
3 NODE_ENV=production forever start server.js
To view the processes, you can use
1 pm2 list
Well done! You deployed your Strapi project on a VPS Server. This article covers the basics of deploying to a VPS, ensure to install and set up nginx reverse proxy to have your app on the web port.
Web and Blockchain Software Engineer who is passionate about using technology towards achieving SDGs, creating innovative solutions, open-source, and building communities. He is building EduKarma for innovative learning in Africa.