
Here’s a step-by-step guide detailing how to install Directus on AlmaLinux VPS.
What is Directus?
Directus is an open-source headless CMS and data platform that allows you to manage and interact with your database through a RESTful API or GraphQL API. It provides a modern, user-friendly admin interface for managing content while keeping full control over your database.
Key Features of Directus
🔹 Database-First Approach
- Directus connects to any SQL database (MySQL, PostgreSQL, SQLite, etc.).
- It does not modify your database structure but extends it with metadata.
- You can use Directus on top of an existing database without migration.
🔹 Headless CMS
- Acts as a back-end-only content management system.
- Front-end agnostic—can be used with React, Vue, Angular, Next.js, etc..
🔹 API-Driven
- Provides both REST and GraphQL APIs.
- Fully customizable API endpoints.
- Built-in role-based access control (RBAC).
🔹 Customizable & Extensible
- Supports custom hooks, extensions, and webhooks.
- Fully open-source with a strong developer community.
🔹 Self-Hosting Options
- Can be self-hosted on a VPS or dedicated server.
- Supports Docker, Kubernetes, and systemd for easy deployment.
How is Directus Different from Other Headless CMSs?
Feature | Directus 🟢 | Strapi 🔵 | Contentful 🟡 |
---|---|---|---|
Database Type | Any SQL (MySQL, PostgreSQL, etc.) | SQLite, PostgreSQL, MongoDB | Managed (proprietary) |
Self-Hosting | ✅ Yes | ✅ Yes | ❌ No |
API Types | REST, GraphQL | REST, GraphQL | REST, GraphQL |
Admin UI | ✅ Auto-generated | ✅ Auto-generated | ✅ Auto-generated |
Open Source | ✅ 100% Free | ✅ (some features paid) | ❌ No (SaaS) |
Directus is ideal for developers who want full control over their database while still benefiting from a modern CMS and API platform.
Who Should Use Directus?
- ✅ Developers who need a customizable API-driven CMS.
- ✅ Teams who want to manage content without locking into a proprietary system.
- ✅ Businesses looking for a self-hosted alternative to SaaS platforms.
- ✅ Projects that require structured database management with an intuitive UI.
Use Cases
- 📌 Enterprise Applications – Manage complex databases with a sleek admin UI.
- 📌 E-Commerce – Handle product catalogs and orders with an API-driven backend.
- 📌 Mobile Apps – Use Directus as a lightweight backend for mobile applications.
- 📌 IoT & Data Management – Store, manage, and analyze structured data easily.
Prerequisites
Ensure that your AlmaLinux VPS meets the following requirements:
- AlmaLinux 8 or AlmaLinux 9 (64-bit)
- Root or sudo access
- At least 2GB of RAM (4GB recommended)
- Node.js (v16 or later)
- A Database (MySQL, PostgreSQL, SQLite, or MariaDB)
- Nginx or Apache (Optional)
- A domain name (Optional, for production setup)
How to Install Directus on AlmaLinux VPS
To install Directus on AlmaLinux VPS, follow the steps below:
-
Update Your System
Before installing Directus, update your system packages:
sudo dnf update -y
-
Install Required Dependencies
Install
wget
,curl
,git
,unzip
, and other dependencies:sudo dnf install wget curl git unzip -y
-
Install Node.js and npm
Directus requires Node.js. Install the latest stable version:
curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash - sudo dnf install -y nodejs
Verify installation:
node -v npm -v
-
Install Database Server
Directus supports MySQL, PostgreSQL, SQLite, and MariaDB. Choose one:
-
Install MySQL (Recommended)
sudo dnf install mysql-server -y sudo systemctl enable --now mysqld
Secure MySQL:
sudo mysql_secure_installation
Create a database and user:
mysql -u root -p
Inside MySQL prompt:
CREATE DATABASE directus; CREATE USER 'directus_user'@'localhost' IDENTIFIED BY 'StrongPassword'; GRANT ALL PRIVILEGES ON directus.* TO 'directus_user'@'localhost'; FLUSH PRIVILEGES; EXIT;
-
For PostgreSQL
sudo dnf install postgresql-server -y sudo postgresql-setup --initdb sudo systemctl enable --now postgresql
Create database and user:
sudo -u postgres psql
CREATE DATABASE directus; CREATE USER directus_user WITH ENCRYPTED PASSWORD 'StrongPassword'; GRANT ALL PRIVILEGES ON DATABASE directus TO directus_user;
Exit with
\q
.
-
-
Install Directus
Now install Directus globally using npm:
npm install -g @directus/cli
Verify the installation:
directus --version
-
Initialize Directus
Navigate to your desired installation directory:
mkdir ~/directus && cd ~/directus directus init
Follow the prompts to configure Directus. Use the database credentials created earlier.
-
Configure Directus
Open the
.env
file inside the Directus directory:nano .env
Modify the database settings as needed. Example for MySQL:
DB_CLIENT=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=directus DB_USER=directus_user DB_PASSWORD=StrongPassword
Save and exit (
CTRL + X
, thenY
, thenENTER
). -
Start Directus
Run the Directus server:
directus start
The output will confirm Directus is running on
http://localhost:8055
. -
Configure a Reverse Proxy (Optional, for Production)
If using Nginx, install it:
sudo dnf install nginx -y sudo systemctl enable --now nginx
Create a Directus configuration file:
sudo nano /etc/nginx/conf.d/directus.conf
Add the following:
server { listen 80; server_name yourdomain.com; location / { proxy_pass http://127.0.0.1:8055; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
Save and restart Nginx:
sudo systemctl restart nginx
-
Access Directus
- Visit
http://yourdomain.com
(if configured with a domain). - If running locally, visit
http://your-server-ip:8055
.
Log in with the credentials you set during installation.
- Visit
Recommended Setup: Running Directus as a Systemd Service & Setting Up Certbot SSL
Now that we know how to install Directus on AlmaLinux VPS, this section will show you how to run Directus as a systemd service for better stability and secure it with SSL using Certbot (requires configuring a fully-qualified domain name for Directus).
-
Create a Systemd Service for Directus
To ensure Directus runs automatically on boot and restarts if it crashes, we will create a systemd service.
-
Create a Service File
sudo nano /etc/systemd/system/directus.service
Add the following content:
[Unit] Description=Directus Headless CMS After=network.target [Service] User=root WorkingDirectory=/root/directus ExecStart=/usr/bin/node /usr/local/bin/directus start Restart=always Environment="NODE_ENV=production" [Install] WantedBy=multi-user.target
💡 Modify paths if your Directus is installed in a different directory.
-
Enable and Start the Service
Reload systemd to apply changes:
sudo systemctl daemon-reload
Enable Directus to start on boot:
sudo systemctl enable directus
Start Directus:
sudo systemctl start directus
Check its status:
sudo systemctl status directus
🔹 If everything is set up correctly, you should see Directus running.
-
-
Set Up SSL with Certbot
To secure Directus with HTTPS, we will install Certbot and obtain a Let’s Encrypt SSL certificate.
-
Install Certbot
First, install the EPEL repository:
sudo dnf install epel-release -y
Now install Certbot and the Nginx plugin:
sudo dnf install certbot python3-certbot-nginx -y
-
Obtain an SSL Certificate
Run the following command (replace
yourdomain.com
with your actual domain):sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
Follow the prompts:
- Enter your email address.
- Agree to the Let’s Encrypt Terms of Service.
- Choose whether to redirect HTTP to HTTPS (Recommended: Yes).
If successful, you will see a message confirming your SSL certificate has been issued.
-
Configure Automatic SSL Renewal
Let’s Encrypt certificates expire every 90 days. Set up automatic renewal:
sudo crontab -e
Add this line at the bottom:
0 3 * * * certbot renew --quiet
This will automatically renew your SSL certificate every night at 3 AM.
-
-
Restart Services
Restart Nginx to apply the changes:
sudo systemctl restart nginx
Restart Directus:
sudo systemctl restart directus
-
Verify HTTPS
Now visit
https://yourdomain.com
in your browser. 🎉
Your Directus installation should be running securely over HTTPS.
Final Notes
- If you face SSL issues, run:
sudo certbot renew --dry-run
This tests renewal without making actual changes.
- To manually restart Directus after updates:
sudo systemctl restart directus
- Monitor Directus logs:
journalctl -u directus -f
Conclusion
We’ve now learned how to install Directus on AlmaLinux VPS, run Directus as a systemd service, and secure Directus installation with Let’s Encrypt SSL with Certbot.
That’s it! 🎉 You now know how to install Directus on AlmaLinux VPS. 🚀 Let us know in the comments if you have any questions or feedback!