Install Directus CMS on Ubuntu 16.04

In this tutorial, we will explain how to install Directus CMS on an Ubuntu 16.04 Cloud with MariaDB, PHP-FPM and Nginx. Directus is an open-source, self-hosted headless CMS that manages your content (not your workflow) written in Backbone.js providing a feature-rich environment for rapid development and management of custom database schemas. This guide should work on other Linux VPS systems as well but was tested and written for an Ubuntu 16.04 Cloud.

Update the system and install necessary packages

ssh user@vps_IP
sudo apt-get update && sudo apt-get -y upgrade
sudo apt-get install software-properties-common nano curl git unzip

Install MariaDB 10.1

To add the MariaDB repository to your sources list and install the latest MariaDB 10.1 server, run the following commands:

>sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,i386] http://ftp.osuosl.org/pub/mariadb/repo/10.1/ubuntu xenial main'
sudo apt-get update
sudo apt-get install -y mariadb-server

When the installation is complete, run the following command to secure your installation:

>mysql_secure_installation

Next, we need to create a database for the Directus installation.

>mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE directus;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON directus.* TO 'directus'@'localhost' IDENTIFIED BY 'strong_password';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> \q

Install PHP, Composer and required PHP modules

To install the latest stable version of PHP version 7.0 and all necessary modules, run:

>sudo apt-get -y install php-fpm php-cli php-json php-curl php-gd php-mysql php-mcrypt php-imagick php-xml

The following commands will set the PHP memory limit to 512MB, change the values of upload_max_filesize and post_max_size to 200M and set the timezone to UTC.

>sudo sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/7.0/fpm/php.ini
sudo sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.0/fpm/php.ini
sudo sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=1/" /etc/php/7.0/fpm/php.ini
sudo sed -i "s/upload_max_filesize = .*/upload_max_filesize = 200M/" /etc/php/7.0/fpm/php.ini
sudo sed -i "s/post_max_size = .*/post_max_size = 200M/" /etc/php/7.0/fpm/php.ini

Composer is a dependency manager for PHP with which you can install packages. Composer will pull in all the required libraries and dependencies you need for your project.

>curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Create a new PHP-FPM pool for your user:

>sudo nano /etc/php/7.0/fpm/pool.d/your_username.conf
[your_username]
user = your_username
group = your_username
listen = /run/php/php7.0-your_username.sock
listen.owner = your_username
listen.group = your_username
listen.mode = 0666
pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 10s
pm.max_requests = 200
chdir = /

Do not forget to change your_username with your username.
Restart PHP-FPM:

>sudo service php7.0-fpm restart

Install Directus

Create a root directory for your Directus using the following command:

>mkdir -p ~/myDirectus.com/public_html

Clone the project repository from GitHub:

>git clone https://github.com/directus/directus.git ~/myDirectus.com

Change to the myDirectus.co directory:

>cd ~/myDirectus.com

Install all PHP dependencies using composer

>composer install

Install and configure Nginx

To install the latest stable version of Nginx available on the Ubuntu repositories, run:

>sudo apt-get -y install nginx

Next, create a new Nginx server block:

>sudo nano /etc/nginx/sites-available/myDirectus.com
>server {
listen 80;
server_name www.myDirectus.com myDirectus.com;
root /home/your_username/myDirectus.com;
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-your_username.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;
}

location ~ /\.ht {
deny all;
}
}

Do not forget to change your_username with your username.

Activate the server block by creating a symbolic link:

>sudo ln -s /etc/nginx/sites-available/myDirectus.com /etc/nginx/sites-enabled/myDirectus.com

Test the Nginx configuration and restart nginx:

>sudo nginx -t
sudo service nginx restart

Open http://myDirectus.com/ in your favorite web browser and you should see the Directus install screen. On this page, you’ll need to select the default language, enter your project name, create an admin user and enter the database details you created earlier. Once you have completed the install, make sure to delete install folder.

That’s it. You have successfully installed Directus on your Ubuntu 16.04 VPS. For more information about how to manage your Directus installation, please refer to the official Directus documentation.


Of course, you don’t have to do any of this if you use one of our Linux Cloud Hosting services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

3 thoughts on “Install Directus CMS on Ubuntu 16.04”

  1. My nginx configuration to avoid mod_rewrite:

    server {
    listen 80;
    listen [::]:80 ipv6only=on;

    root /home/your_username/myDirectus.com;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name www.yourdomain.com yourdomanin.com;
    sendfile off;

    location /api {
    if (!-e $request_filename) {
    rewrite ^/1/extensions/([^/]+) /api/api.php?run_extension=$1 last;
    }
    rewrite ^ /api/api.php?run_api_router=1 last;
    }

    location / {
    try_files $uri $uri/ /index.php$args;
    }

    # Force this file extension to be output as text
    location ~ ^/(media|storage)/.*\.(php|phps|php5|htm|shtml|xhtml|cgi.+)?$ {
    add_header Content-Type text/plain;
    }

    # No direct access to extension api file
    location ~* [^/]+/customs/extensions/api\.php$ {
    return 403;
    }

    # No direct access to customs api endpoints files
    location ~* /customs/endpoints/ {
    deny all;
    }

    error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root /home/your_username/myDirectus.com;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/run/php/php7.0-cesa.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    # deny access to .htaccess files, if Apache’s document root
    # concurs with nginx’s one
    #
    location ~ /\.ht {
    deny all;
    }
    }

    Reply
  2. Nice guide, worked perfectly. Just a couple of kinks.
    Add apt install unzip to the system packages. It’s required later for composer to install the dependencies.
    And since mod_rewrite isn’t working properly. Manuel Cesarini’s nginx config file works perfectly. Just make sure to change the php7 socket to your_username.sock (it’s cesa on his config file)

    Everything else is working in order. Just tested it on a vanilla 16.04 x64 ubuntu server.

    Reply

Leave a Comment