How To Install Strapi on Ubuntu 24.04
Strapi is a popular open-source headless CMS built on Node.js that lets you easily manage content for websites, mobile apps, and APIs. This guide explains how to deploy Strapi fully automated on Ubuntu 24.04, including Node.js installation, project setup, service creation, and firewall configuration.
Step 1: Update and Upgrade System Packages
Ensure your system is up-to-date:
sudo apt update && sudo apt upgrade -y
This step updates your package cache and upgrades installed packages to their latest versions.
Step 2: Install Required Packages
Install all required dependencies for Strapi:
sudo apt install -y curl git build-essential libssl-dev sqlite3 libsqlite3-dev
-
curl
andgit
: for downloading and cloning Strapi projects -
build-essential
andlibssl-dev
: for compiling native Node.js modules
-
sqlite3
andlibsqlite3-dev
: for lightweight database storage
Step 3: Install Node.js LTS
Strapi requires Node.js. This guide uses Node.js 20 LTS:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash -
sudo apt install -y nodejs
Step 4: Install Yarn Globally
Strapi uses Yarn for dependency management:
sudo npm install -g yarn
Step 5: Create a Strapi User and Directory
For security, create a dedicated system user for Strapi:
sudo useradd -m -s /bin/bash strapi
sudo mkdir -p /opt/strapi
sudo chown strapi:strapi /opt/strapi
Step 6: Create a Strapi Project (Non-Interactive)
Run as the Strapi user to create a project quickly:
sudo -u strapi bash -c "
cd /opt/strapi
mkdir -p my-strapi-app
cd my-strapi-app
npx create-strapi@latest . --quickstart --no-run --yes
"
This creates a ready-to-use Strapi project in /opt/strapi/my-strapi-app
.
Step 7: Install Project Dependencies
Install all required Node.js packages:
sudo -u strapi bash -c "
cd /opt/strapi/my-strapi-app
yarn install --check-files
"
Step 8: Build the Admin Panel
Strapi’s admin panel must be built before running:
sudo -u strapi bash -c "
cd /opt/strapi/my-strapi-app
yarn build
"
Step 9: Start Strapi for the First Time
Run Strapi in the background to generate logs:
sudo -u strapi bash -c "
cd /opt/strapi/my-strapi-app
nohup yarn start > strapi.log 2>&1 &
"
Step 10: Configure Strapi as a Systemd Service
Create /etc/systemd/system/strapi.service
:
[Unit]
Description=Strapi Headless CMS
After=network.target
[Service]
Type=simple
User=strapi
WorkingDirectory=/opt/strapi/my-strapi-app
ExecStart=/usr/bin/yarn start
Restart=on-failure
RestartSec=5
Environment=NODE_ENV=production
Environment=PORT=1337
[Install]
WantedBy=multi-user.target
Reload systemd and enable Strapi:
sudo systemctl daemon-reload
sudo systemctl enable --now strapi
Step 11: Open Strapi Port in Firewall
Allow the default Strapi port (1337) through UFW:
sudo ufw allow 1337/tcp
sudo ufw status
Step 12: Verify Installation
Check Strapi service status:
sudo systemctl status strapi
Open a browser and visit:
http://<YOUR_SERVER_IP>:1337/admin
Conclusion
By following these steps, you have a fully automated Strapi deployment on Ubuntu 24.04, complete with:
-
Node.js LTS and Yarn installed
-
Project setup and dependency installation
-
Admin panel build
-
Systemd service for background management
-
Firewall rules allowing access to Strapi
You can now focus on creating content and building applications on top of your Strapi backend.