Directus is a free and open source headless content management system written in Backbone.js that provides a feature-rich environment for fast development and management of custom database schemas.
It is used to manages your content and providing a feature-rich environment for rapid development and management of custom database schemas.
In this tutorial, we will explain how to install Directus CMS on an Ubuntu 16.04 server with MariaDB, PHP-FPM and Nginx.
Update the System
Before installing any packages, it is recommended to update your system with the latest stable version. You can do this with the following commands:
sudo apt-get update -y
sudo apt-get upgrade -y
Once your system is up to date, you can proceed to install the Apache web server.
Install Nginx
First, you will need to install Nginx web server to your system. You can install it with the following command:
sudo apt-get install nginx
Once Nginx is installed, start the Nginx service and enable it to start on boot with the following command:
sudo systemctl start nginx
sudo systemctl enable nginx
Install PHP and PHP-FTP
Next, you will need to install PHP, PHP-FPM and other required PHP modules to your system. You can install all of them by running the following command:
sudo apt-get -y install php7.0 php7.0-fpm php7.0-cli php7.0-json php7.0-curl php7.0-gd php7.0-mysql php7.0-mcrypt php7.0-imagick php7.0-xml
Once all the packages are installed, you will need to make some changes in php.ini file:
sudo nano /etc/php/7.0/fpm/php.ini
Change the following lines:
memory_limit = 512M
date.timezone = UTC
cgi.fix_pathinfo = 1
upload_max_filesize = 200M
post_max_size = 200M
Save and close the file when you are finished.
Next, you will also need to install Composer to your system. Composer is a dependency manager for PHP with which you can install packages.
You can install it with the following command:
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
Next, create a new PHP-FPM pool for your user.
sudo nano /etc/php/7.0/fpm/pool.d/www-data.conf
Add the following lines:
[www-data]
user = www-data
group = www-data
listen = /run/php/php7.0-www-data.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0666
pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 10s
pm.max_requests = 200
chdir = /
Save and close the file then restart PHP-FPM servcie with the following command:
sudo systemctl restart php7.0-fpm
Install and Configure MariaDB
You will need to install MariaDB server to store data. You can install it with the following command:
sudo apt-get install mariadb-server -y
Start MariaDB and enable it to automatically start at boot time.
sudo systemctl start mysql
sudo systemctl enable mysql
By default, MariaDB is not secured, so you will need to secure it first. You can secure it by running the mysql_secure_installation script.
sudo mysql_secure_installation
Answer all the questions as shown below:
Set root password? [Y/n] n
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
Once MariaDB is secured, log in to the MySQL shell and create a database for Directus:
mysql -u root -p
Enter your root password when prompt, then create a database for Directus. It is recommended to set secure password:
MariaDB [(none)]>CREATE DATABASE directus_db;
Query OK, 1 row affected (0.00 sec)
Next, create a username and password for directus with the following command:
MariaDB [(none)]>CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
Query OK, 1 row affected (0.00 sec)
Next, grant privileges to the Directus database with the following command:
MariaDB [(none)]>GRANT ALL PRIVILEGES ON directus_db.* TO 'user'@'localhost';
Query OK, 1 row affected (0.00 sec)
Next, you will need to run the FLUSH PRIVILEGES command so that the privileges table will be reloaded by MariaDB and we can use new credential:
MariaDB [(none)]>FLUSH PRIVILEGES;
Query OK, 1 row affected (0.00 sec)
Next, exit from the MariaDB console with the following command:
MariaDB [(none)]>\q
Once you are done, you can proceed to the next step.
Install Directus
First, you will need to download the latest version of the Directus from Git Hub repository.
You can do this by running the following command:
git clone https://github.com/directus/directus.git /var/www/html/directus
Once the download is complete, install all PHP dependencies using composer.
cd /var/www/html/directus/
composer install
Next, give proper permission to the directus directory:
sudo chown -R www-data:www-data /var/www/html/directus/
Configure Nginx for Directus
Next, you will need to create a virtual server block for Directus. You can do this by creating directus.conf file inside /etc/nginx/sites-available/ directory.
sudo nano /etc/nginx/sites-available/directus.conf
Add the following lines:
server {
listen 80;
server_name www.yourdomain.com;
root /var/www/html/directus;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php;
}
access_log /var/log/nginx/directus.access.log;
error_log /var/log/nginx/directus.error.log;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-www-data.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
Save and close the file, then activate the server block by creating a symbolic link:
sudo ln -s /etc/nginx/sites-available/directus.conf /etc/nginx/sites-enabled/
Nest the Nginx configuration and restart nginx service with the following command:
sudo nginx -t
sudo systemctl restart nginx
Access Directus
Before accessing the Directus Web Interface, you will need to allow HTTP service through UFW firewall.
By default UFW is disabled on your system, so you need to enable it first. You can enable it with the following command:
sudo ufw enable
Once UFW firewall is enabled, you can allow HTTP service by running the following command:
sudo ufw allow http
You can now check the status of UFW firewall by running the following command:
sudo ufw status
Next, Open your web browser and type the URL http://yourdomain.com. You should be redirected to the Directus install screen. Next, complete the required steps to finish the installation.
That’s it. You have successfully installed Directus on your Ubuntu 16.04 server.