✨ Strapi MCP is now Generally Available - let your agents manage your Strapi content ✨

How tos5 min read

How to deploy a Strapi API on Ubuntu 16.04

January 31, 2018Updated on July 10, 2026

Please note: Since we initially published this blog post, we released new versions of Strapi and tutorials may be outdated. Sorry for the inconvenience if it's the case. Please help us by reporting it here. Please follow the official documentation for deploying your Strapi project.

Strapi is a Node.js Content Management Framework dedicated to API creation. Halfway between a Node.js Framework and a Headless CMS, it has been designed to build APIs in seconds instead of weeks thanks to its built-in features: Admin Panel, Authentication & Permissions management, Content Management, API Generator, etc.

Hosting a Strapi project is an important mission during both development and production phases. However, as a developer, you are probably more an expert in JavaScript than DevOps. Don't worry, this article is here to help you.

In this tutorial, you will learn how to deploy a Strapi v3 project for production on a clean Ubuntu server.

Prerequisites

First of all, you will need the following a clean Ubuntu 16.04 server, configured with git installed on it a non-root user having the sudo privileges.

Install Node.js

A Strapi app is nothing else than a Node.js application. Obviously, it requires Node.js (8 or higher).

Run the following commands to install Node.js:

$ curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
$ sudo apt-get install -y nodejs

Check that Node has been successfully installed:

$ node -v

It should print v9.x.x.

Install MongoDB

Strapi uses MongoDB as the default database system. Except if you decided to use another database system or host the MongoDB database on another server or service (what we strongly recommend), you have to install MongoDB on the Ubuntu server.

Import the public key:

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6

Create a list file:

$ echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

Reload local package database:

$ sudo apt-get update

Install MongoDB packages:

$ sudo apt-get install -y mongodb-org

Start MongoDB:

$ sudo service mongod start

If you have any issue here, give a look at the MongoDB documentation.

Note: by default, MongoDB is automatically accessible from outside through port 27017. We highly advise you to restrict access by adjusting your Firewall rules.

Setup your project

Node.js and MongoDB are installed. It's time to import our Strapi project.

Move to your user's home directory and clone a Strapi project from a GitHub (or GitLab, BitBucket...) repository.

Clone your project:

$ cd ~
$ git clone https://github.com/strapi/sample-strapi-app

Except if you want to get a clean Strapi app, replace the URL above by one of your projects.

Note: if your project is hosted in a private repository, the terminal may prompt your credentials (email and password).

Install dependencies:

$ cd sample-strapi-app
$ npm install --production

Start the server to make sure everything is going well:

$ NODE_ENV=production npm start

Note: NODE_ENV=production informs Strapi that the app is running in production mode. The configuration files taken into consideration are the ones located in config/environments/production.

Your Strapi API should be accessible at the following URL: http://yourIP:1337.

Then, stop the server by running ctrl + c.

Install PM2

As you may have seen, if you quit the npm start script or exit the SSH connection, the Node.js process is stopped. This is quite annoying. Also, we want to be sure the app will be automatically restarted if it crashes.

This is where PM2, the de-facto process manager for Node.js, comes to the rescue.

Install PM2:

$ npm install pm2 -g

Note: if you encounter npm permissions issues, change the permissions to npm default directory or use sudo.

Start your Strapi server:

$ NODE_ENV=production pm2 start server.js --name api

Your Strapi API should be accessible at the following URL: http://yourIP:1337.

List the processes:

$ pm2 list

To make sure your API is running well, check out the logs:

$ pm2 logs api

Press crtl + c to leave the logs view.

Note: take a look at the PM2 documentation for more advanced usage.

Install nginx

Your application is now up and running on port 1337. To make it accessible on the web port (80) you need to install a reverse proxy.

For this tutorial, we are going to use nginx: the most famous HTTP and reverse proxy server.

Install it:

$ sudo apt-get update
$ sudo apt-get install -y nginx

Open the main configuration file:

$ sudo nano /etc/nginx/sites-available/default

Next, replace the content in the location / directive by the following:

proxy_pass http://localhost: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;

Restart nginx:

$ sudo systemctl restart nginx

At this point, your Strapi API should be accessible at the following URL: http://yourIP.

Additional Resources

Next Steps

  • Implement Automated Backups: Ensure your data is safe by setting up regular backups of your database.
  • Enhance Security: Consider setting up a firewall using UFW and configuring fail2ban to protect against brute-force attacks.
  • Scale Your Application: Explore containerization with Docker and orchestration with Kubernetes for scaling.

Conclusion

Congratulations, you successfully deployed a Strapi application on a clean Ubuntu server!

This tutorial covers the basic parts to deploy a Strapi application. We strongly advise you take the following points into high consideration: security (open ports, IP restrictions, etc.), SSL, auto-scaling, etc.

To make your life even easier, we published a complete bash script to set up your environment. This script installs Node.js, Strapi, PM2, MongoDB, and nginx (correctly configured). To try it, run the following command: wget -qO - https://strapi.io/install.sh | sudo -E bash && source ~/.bashrc on a clean Ubuntu server. After running it, the only thing you need to do is to set up your own Strapi project or create a new one through the CLI.

In the next few weeks, we will publish other articles relating to Strapi APIs deployments: Deploy a Strapi on Heroku, Using mLab with Strapi, Using Strapi with Docker, Monitor a Strapi API with Keymetrics, etc.

What tutorials would you like next?

Pierre BurgyChief Executive Officer

Pierre created Strapi with Aurélien and Jim back in 2015. He's a strong believer in open-source, remote and people-first organizations. You can also find him regularly windsurfing or mountain-biking!

Related Posts

EcosystemBeginner·7 min read

6 Top Deployment Options For Your Strapi Application

If you are considering a deployment option for your Strapi project and are stuck with many possibilities, here is a guide to help you choose one.

·November 14, 2022
Community·2 min read

Deploy a Next.js Blog Starter Using Strapi on Vercel - Online Meetup Recap #4

Shu Uesugi, Product engineer at Vercel, joined me (Maxime Castres, Growth Hacker at Strapi) for a virtual meetup last...

·May 19, 2020
Releases & Roadmap·7 min read

Announcing the Strapi 5 Beta

We've been on an incredible journey, and today, we're thrilled to announce a major milestone: Strapi 5 is officially in Beta! 🚀

·March 25, 2024