5 min read

Directus installation guide on oracle cloud using docker

Directus installation guide on oracle cloud using docker

Hi good people! In my other post, I reviewed Directus which is a headless data platform and can be used as a backend API with a built-in data studio (admin panel). I highly recommend you read that post if you are new to Directus.

In this post, I will guide you on how to install Directus using docker on Oracle Cloud. We will be using aaPanel which is a great free and stable server control panel. If you haven't heard of it, I have a review and a full installation guide available for you.

Pre-requisites

  • Oracle VM with aaPanel installed. Click here for the aaPanel installation guide.
  • Some docker knowledge
  • Domain name added to Cloudflare, and Origin server certificate
  • Google account for backup

Step 1: Install the docker in aaPanel

You can skip this if you already have docker installed. Otherwise, follow the steps below.

  • log in to the panel
  • go to the App stores of the panel
  • search for docker
  • install Docker manager

Step 2: DNS setup

Since DNS will take some time to propagate, we will start with the domain. I recommend using Cloudflare as they have free features with free origin server certificates.

  • Log in to the Cloudflare dashboard
  • Add your domain to Cloudflare if you have not done yet
  • Add an A record to the server's public IP address. If you are planning to use the root domain, use @ in the name. I will be using a subdomain.
  • Be sure to check the proxy status is On.
  • Go to the SSL/TLS section of your domain, and click origin server. Now create a cretificate for your domain. After generating, save the Private key and Certificate in a file. We will need these to install SSL and reverse proxy later.

Step 3: Set up MySQL database

Come back to the aaPanel. In this step, we will create a database for directus. Follow the steps.

  • Navigate to the database and click Add Database
  • Write the DB Name: directus, username: directus, permission: specified IP and write down your server public IP.
  • Click Submit.

This will create a database. Don't forget to change the DB name, username, and password according to your choice.

Step 4: Docker compose template

In this step, we will write a docker-compose file with all the required configuration options of Directus and persistent storage with docker volume.

We will create a YAML file in a directory called 'directus' under the /www directory. Later we will configure the required volume in this directory and finally back up this folder. So all our volume files and YAML file will be backed up.

Follow steps:

  • In aaPanel, navigate to Files and go to /www directory
  • create a directory named 'directus'
  • create a file docker-compose.yaml under directus folder
  • double click to edit the file and paste the following code
version: '3'
services:

  directus:
    container_name: directus
    image: directus/directus:9.20.4
    restart: always
    ports:
      - 8055:8055
    volumes:
      # By default, uploads are stored in /directus/uploads
      # Always make sure your volumes matches the storage root when using
      # local driver
      - ./uploads:/directus/uploads
      # Make sure to also mount the volume when using SQLite
      # - ./database:/directus/database
      # If you want to load extensions from the host
      #- ./extensions:/directus/extensions
    environment:
      KEY: '255d861b-5ea1-5996-9aa3-7f6rg47h-922530ec40b1'
      SECRET: '6116487b-cda1-52c2-fu75hk-b5b5-c8022c45e263'

      DB_CLIENT: 'mysql'
      DB_HOST: 'server_public_ip'
      DB_PORT: '3306'
      DB_DATABASE: 'directus'
      DB_USER: 'directus'
      DB_PASSWORD: 'mysql_password'

      ADMIN_EMAIL: '[email protected]'
      ADMIN_PASSWORD: 'd1r3ctu5'

      # Make sure to set this in production
      # (see https://docs.directus.io/self-hosted/config-options#general)
      PUBLIC_URL: 'https://directus.example.com'

Please change the DB configuration, key, secret, and admin credentials according to your need. You can also add additional environmental variables here to configure Directus. Full options here.

Step 5: Run the container

To run the container in aaPanel, you must first import the compose file.

  • Navigate to Docker > compose template.
  • Now click add and select the local template tab.
  • Enter /www/directus in the search box and click search. You must see the newly created yaml file. Select it from the list and submit it.

Then we need to pull the image. On the same page, click the pull image link of the directus template. A directus (v9.20.4) image will be pulled based on the image we specified in yaml file.

Now it's time to run a container from the pulled image. To do so-

  • Navigate to Docker > Container in the aaPanel
  • Click Add Container and chose the compose tab.
  • Select directus from the dropdown and enter a name.
  • After submitting the dialog, a new container will be created and listed.
  • Wait for a minute or two (give some time to boot up directus) and see the log of the container. In the log, you must see 'Server started at http://0.0.0.0:8055' which indicates your directus is running successfully.

Step 6: Open the port on the security group

On the docker-compose file, we exposed the 8055 port on the host. So we need to open this port. Follow this instruction. Make sure MySQL port 3306 is there.

Next, come back to aaPanel to release ports from inside the server. Go to the security page, and open the 8055 ports in the Firewall section. For example, type 8055 in the port, directus in the description, and click open. Do a similar thing for other ports if not already there.

At this stage, you should see a running directus on URL: http://server_public_ip:8055

You can now log in with the credentials you specified in yaml file and see if everything is working or not. For example, try to upload a file. If the upload does not succeed, you should change the upload directory permission inside /www/directus directory. Try the following code:

sudo chown -R 1000:1000 ./uploads

Step 7: Reverse proxy with Nginx

In this step, we will set up a reverse Nginx proxy. It will proxy all the requests from our domain to http://localhost:8055. To configure SSL, we need a Cloudflare origin server certificate from step 2.

  • Go to the website page on aaPanael, and click add site under PHP project.
  • Enter the domain, FTP - no, Database - No, PHP version - static, and click submit. Refresh the page, you can see a new site is created.
  • Click the site name. The site config dialog will open.
  • Go to SSL > Other certificate, paste the Private key and Certificate and Save.
  • Turn On the Force HTTPS option.
  • Go to the Reverse proxy section and add a proxy.
  • Enter the proxy name: directus, target URL: http://localhost:8055, and submit.

Test your domain in the browser and you should see your new directus website. Now you have successfully configured a reverse proxy for the directus docker container. The next step is optional but very important.

Step 8: Configure backup

In this section, we will configure a backup for our newly created directus with cron. In aaPanel, there are several plugins for that - Google Drive, S3, and remote FTP. Feel free to use whatever you like. But I would go for Google Drive.

First, you have to install the plugin in aaPanel. Go to App Store, search for google drive and install the plugin. After installation, click the settings. Complete the Google Drive verification process according to the instruction.

Now we will create 2 cron tasks for the backup - one for the database and the other for the directory (/www/directus) in our server.

Database Backup

Go to the Cron page of aaPanel and add a task according to the instruction:

  • Type of Task: Backup Database
  • Execution cycle: choose how you want to backup
  • Backup database: select the directus or all
  • Backup to: Google Drive
  • save the task

Directory Backup

Go to the Cron page of aaPanel and add a task according to the instruction:

  • Type of Task: Backup Directory
  • Execution cycle: choose how you want to backup
  • Directory to backup: select /www/directus/
  • Backup to: Google Drive
  • save the task

The tasks will now be available in the task list. To test a task, click execute link and wait for some time. You will see your backup is now uploaded to Google Drive.


Congratulations! You now successfully installed a directus instance on oracle cloud and configured the SSL, reverse proxy, and backup strategy to Google Drive. Now go to your directus admin panel by visiting yourdomain.com