How to Install Discourse on Ubuntu 22.04

Discourse is a modern, open-source community discussion platform or forum system. This article step-by-step describes how to set up your own Discourse Forum Server with a free SSL Certificate from Let's Encrypt on Ubuntu 22.04.

How to set up Discourse with a free SSL Certificate​

Prerequisites​

Before you begin with the Discourse installation:
  • Deploy a new Ubuntu 22.04 cloud server with at least 2 GB of RAM.
  • Set up an SMTP server for Discourse emails. You can register for a transactional email account from external email providers such as Mailgun or Sendgrid. Discourse has a list of recommended email providers.
  • You'll need a fully-qualified domain name (FQDN) such as discourse.example.com to create an SSL certificate with Let's Encrypt.
    Create an FQDN at your DNS provider and point the name to the IP address of your server instance. It may take some time for the name to propagate through the DNS system. Use a DNS checking site to ensure the name has fully propagated before proceeding.

1. Secure the Server​

Turn on automatic security updates.

$ sudo dpkg-reconfigure -plow unattended-upgrades

Set up a firewall with ufw.

$ sudo apt-get install ufw
$ sudo ufw default allow outgoing
$ sudo ufw default deny incoming
$ sudo ufw allow 22 comment 'SSH'
$ sudo ufw allow http comment 'HTTP'
$ sudo ufw allow https comment 'HTTPS'
$ sudo ufw enable

Install fail2ban to secure your server
$ sudo apt install fail2ban

Configure fail2ban to Use ufw

Copy the main configuration to avoid unexpected changes during package updates.
$ sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
Edit the configuration file with your favorite text editor
$ sudo nano /etc/fail2ban/jail.local
Change the banaction and banaction_allports settings to ufwin the file /etc/fail2ban/jail.local as follows:
banaction = ufw
banaction_allports = ufw

2. Collect the SMTP Details​

Next, you'll need to collect the SMTP details from your transactional email account.

You need the following information:
  • SMTP server address
  • SMTP port
  • SMTP user name
  • SMTP password

3. Access Your Vultr VPS​

Connect to your server instance with SSH. For example, if your server's IP address is 192.0.2.120:
$ ssh root@192.0.2.123

4. Install Docker​

Docker is an open-source platform for developing, shipping, and running applications. Docker enables you to run Discourse in an isolated and optimized environment. Use these steps to install Docker on your server.

Uninstall old versions such as docker, docker.io, or docker-engine.
$ sudo apt-get remove docker docker-engine docker.io containerd runc
Set up the repository.

$ sudo apt-get update
$ sudo apt-get install ca-certificates curl gnupg lsb-release
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$ sudo apt update

Install the latest version of Docker Engine.
$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

5. Install Discourse​

Create a 'discourse' folder in the /var directory.
$ mkdir /var/discourse
Clone the official Discourse git repository in /var/discourse.
$ git clone https://github.com/discourse/discourse_docker.git /var/discourse
Change to the Discourse directory.
$ cd /var/discourse
Launch the setup tool.
$ ./discourse-setup
  • Answer the prompted questions with your hostname and SMTP details. The Discourse setup script may ask the following questions:
    • The hostname for your Discourse?: Enter your chosen hostname for your Discourse platform (for example, discourse.example.com).
    • Email address for the admin account(s)?: Choose the email address for your Discourse admin account. It can be any email address. When setting up the Discourse control panel, you need to reuse this email address.
    • SMTP server address?: Enter your SMTP server address. For example, the SMTP server address for Sendgrid is smtp.sendgrid.net
    • SMTP port?: Enter your SMTP port. For example, the SMTP port is 587.
    • SMTP user name?: Enter your SMTP user name. For example, Mailgun provides you with a user name. For Sendgrid, you must set the user name precisely to the string apikey.
    • SMTP password?: Enter your SMTP user password. For example, Mailgun provides you with a password. For Sendgrid, you can enter your generated API key.
  • Press ENTER to confirm your settings, and the installation process begins automatically. The setup tool requests a Let's Encrypt SSL certificate by default.
You can run ./discourse-setup again if you need to change these settings.

6. Start Discourse​

To access your Discourse instance, use a web browser to navigate to your domain name, then follow the setup wizard to register your admin account.

7. Upgrade Discourse​

Visit https://your_hostname/admin/upgrade, then click Upgrade to the Latest Version and follow the instructions.

Or, you can upgrade Discourse from the command line as follows:

Change directory to /var/discourse
$ cd /var/discourse
Get the latest version of Discourse
$ sudo git pull
Rebuild the Discourse app
$ sudo ./launcher rebuild app

Additional Configurations and Settings​

1. Modify email settings​

  1. Run cd /var/discourse
  2. Run ./discourse-setup
  3. Edit SMTP-related settings as needed
  4. Done.

2. Install Plugins in Discourse​

This tutorial requires an understanding of how to use GitHub repos, specifically, how to get or copy the git clone URL and how to edit YAML (*.yml) files via the terminal using Nano, specifically how to save and exit on Nano.

YAML files strongly follow indentations, so be sure to respect these as you copy-paste and edit the necessary *.yml for your Discourse instance.
Copy the plugin’s GitHub git clone URL.

Access your container’s app.yml file (present in /var/discourse/containers/)
cd /var/discourse
nano containers/app.yml
Add the plugin’s repository URL to your container’s app.yml file:

hooks:
after_code:
- exec:
cd: $home/plugins
cmd:
- sudo -E -u discourse git clone https://github.com/discourse/docker_manager.git
- sudo -E -u discourse git clone https://github.com/discourse/discourse-spoiler-alert.git

Add the plugin’s git clone URL just below the line containing the git clone https://github.com/discourse/docker_manager.git

Follow the existing format of the docker_manager. git line; if it does not contain sudo -E -u discourse then insert - git clone https://github.com/discourse/discourse-spoiler-alert.git

Rebuild the container:

cd /var/discourse
./launcher rebuild app

That’s it, you’ve successfully installed the plugin on your Discourse instance!

3. How to uninstall a plugin​

To remove a plugin, remove the line - git clone https://github.com/... from your app.yml file and rebuild your site via

cd /var/discourse
./launcher rebuild app
 

About us

  • oDiscuss Community provides a forum platform for discussing, sharing resources and ideas, and finding answers on various topics, including technology, IT, IT systems, networking systems, computers, servers, blogging, digital marketing, SEO, web design, web development, and more.

Quick Navigation

User Menu