How to Install Directus on Linux Mint Latest

Directus is an open-source headless CMS (Content Management System) that provides a customizable API and intuitive interface for managing and delivering content. In this tutorial, we will guide you through the installation process of Directus on the latest version of Linux Mint.

Prerequisites

Before we begin with the installation, ensure that you have the following requirements:

Step 1: Install Composer

Composer is a dependency manager for PHP. It is used to manage Directus's dependencies and to install the application. To install Composer, use the following commands:

$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
$ sudo chmod +x /usr/local/bin/composer

Step 2: Install Directus

The following commands will acquire the latest version of Directus and install it in the directus folder in the /var/www directory.

$ sudo mkdir -p /var/www/directus 
$ sudo chown -R $USER:$USER /var/www/directus
$ cd /var/www/directus
$ composer create-project directus/directus

Step 3: Configure the Directus Environment

The following command will generate a new .env file in which you can configure Directus.

$ cd directus
$ cp ./example.env ./custom.env
$ nano ./custom.env

Here, you can replace APP_ENV, APP_KEY, DATABASE_URL, and other parameters according to your requirements. Save and close the file.

Once the .env file is saved, run the following commands:

$ php artisan migrate
$ php artisan install --email=admin@example.com --password=password

These commands will start the initialization process of Directus and will create the default admin account.

Step 4: Configure Nginx or Apache

Depending on your preference and your installed webserver, you need to configure a virtual host for Directus. Below is an example configuration for Nginx servers:

server {
    listen 80;
    server_name directus.example.com;

    root /var/www/directus/public;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTP_PROXY "";
        fastcgi_intercept_errors off;
    }

    location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|swf)$ {
        expires 30d;
        access_log off;
    }

    location ~* \.(?:css|js)$ {
        try_files $uri /index.php?$query_string;
        expires 1y;
        access_log off;
        add_header Cache-Control "public";
    }

    location /api {
        rewrite ^/api/(.*)$ /$1 break;
        proxy_pass http://127.0.0.1:8055; #change this to the port you have configured in the .env file
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

The above configuration sets up a virtual host for Directus and redirects all requests to Directus's API endpoint to the port specified in the .env file. Additionally, all static files such as images, CSS, and JS are cached for faster page load times.

Step 5: Restart the Web Server

After making the necessary changes to the Nginx or Apache configurations, restart your webserver by running the following commands:

$ sudo systemctl restart nginx

or

$ sudo systemctl restart apache2

Conclusion

That's it! In this tutorial, you learned how to install Directus on Linux Mint and configure it with a web server. Once you have launched Directus and set it up, you have access to a powerful API and user interface to manage and deliver content.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!