RHEL BasedRocky Linux

How To Install Discourse on Rocky Linux 9

Install Discourse on Rocky Linux 9

In this tutorial, we will show you how to install Discourse on Rocky Linux 9. For those of you who didn’t know, Discourse is a powerful platform for online discussions and forums and is a great choice for communities and organizations that want to foster engaging and productive discussions. Discourse is written in Ruby on Rails and uses a modern web architecture that includes real-time updates, a mobile-friendly design, and a sophisticated API. It is highly customizable and offers a range of features that are designed to make online discussions engaging, productive, and accessible.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Discourse open-source community discussion platform on Rocky Linux. 9.

Prerequisites

  • A server running one of the following operating systems: Rocky Linux 9.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Discourse.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Discourse on Rocky Linux 9

Step 1. The first step is to update your system to the latest version of the package list. To do so, run the following commands:

sudo dnf check-update
sudo dnf install dnf-utils epel-release

Step 2. Installing Git.

By default, Git is available on Rocky Linux 9 AppStream repository. Now run the following command below to install the stable version of Git to your system:

sudo dnf install git

You can verify the installed version by using the command below:

git --version

Now we set up standard settings such as names and e-mails, mainly around git commit messages:

git config --global user.name "idroot"
git config --global user.email "godetz@idroot.us"

To verify that your name and email have been configured:

git config --list

For additional resources on installing Git, read the post below:

Step 3. Installing Docker.

By default, Docker is not available on Rocky Linux 9 base repository. Now run the following command below to add the Docker CE repository to your system:

sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo

After the repositories have been added to the system, now run the following command to install Docker CE Rocky Linux:

sudo dnf install docker-ce docker-ce-cli containerd.io docker-compose-plugin --allowerasing

Once the installation is completed, start the Docker service on your Rocky Linux and also enable it to run automatically with system boot:

sudo systemctl enable docker
sudo systemctl start docker

Next, add the user to the Docker group using the command:

sudo usermod -aG docker $USER

Then, create a new group:

newgrp docker

Verify the Docker version is installed:

docker version

For additional resources on installing Docker, read the post below:

Step 3. Download Discourse.

First, we clone the official Discourse Docker GitHub repository to the /var/discourse directory:

sudo git clone https://github.com/discourse/discourse_docker.git /var/discourse

Next, change to the Discourse directory and remove writing and executable permissions from the containers directory:

cd /var/discourse
sudo chmod 700 containers

Step 4. Configure Discourse.

After downloading the Discourse Docker image, the next step is to configure it. You can do this by editing the containers/app.yml file. Here is an example of how you can configure the file:

cp samples/standalone.yml containers/app.yml
nano containers/app.yml

Set the variable DISCOURSE_HOSTNAME to the domain name:

DISCOURSE_HOSTNAME: 'your-domain.com'

Change the line "80:80 to "8080:80". This will change the external HTTP port for Discourse to 8080 since we will use Nginx at port 80. Comment out the "443:443":

expose:
  - "8080:80"   # http
 #- "443:443"   # https

Set the email for your administrator:

DISCOURSE_DEVELOPER_EMAILS: 'idroot@your-domian.com,admin@your-domian.com'

Set up SMTP settings:

ISCOURSE_SMTP_ADDRESS: smtp.your-domain.com
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: user@your-domain.com
DISCOURSE_SMTP_PASSWORD: your-strong-smtp-password
#DISCOURSE_SMTP_ENABLE_START_TLS: true           # (optional, default true)
DISCOURSE_SMTP_DOMAIN: your-domain.com    # (required by some providers)
DISCOURSE_NOTIFICATION_EMAIL: noreply@your-domain.com    # (address to send notifications from)

Step 5. Installing Discourse on Rocky Linux 9.

After the configuration file is set up, we can start Discourse using the following command below:

sudo ./launcher bootstrap app

Start Discourse application:

sudo ./launcher start app

Step 6. Installing and configuring Nginx for Discourse.

By default, Nginx is not available on Rocky Linux 9 base repository. Now run the following command below to add Nginx stable repository to your system:

sudo tee /etc/yum.repos.d/nginx-stable.repo<<EOF
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/9/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF

Now, run the following command to install the latest stable version of Nginx to your server:

sudo dnf update
sudo dnf install nginx

Once the installation is done, start the Nginx service and enable it to automatically start on reboot all in one go with:

sudo systemctl enable --now nginx

To verify that the latest version of Nginx has been installed, run:

nginx -v

Here’s an example of how to configure Nginx to serve Discourse:

nano /etc/nginx/conf.d/discourse.conf

Add the following file:

# enforce HTTPS
server {
    listen       80; 
    listen 		[::]:80;
    server_name  discourse.example.com;
    location / { return 301 https://$host$request_uri; }
}
server {
    listen       443 ssl http2;
    listen 		[::]:443 ssl http2;
    server_name  discourse.example.com;

    access_log  /var/log/nginx/discourse.access.log;
    error_log   /var/log/nginx/discourse.error.log;
    
    
    http2_push_preload on; # Enable HTTP/2 Server Push
    # Enable TLSv1.3's 0-RTT. Use $ssl_early_data when reverse proxying to
    # prevent replay attacks.
    #
    # @see: https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_early_data
    ssl_early_data on;
    
    # Security / XSS Mitigation Headers
    # NOTE: X-Frame-Options may cause issues with the webOS app
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";
    add_header X-Early-Data $tls1_3_early_data;
    
    client_max_body_size 100m;
    
    location / {
        proxy_pass http://your-domain.com:8080/;
        proxy_set_header Host $http_host;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
    }    
}

# This block is useful for debugging TLS v1.3. Please feel free to remove this
# and use the `$ssl_early_data` variable exposed by NGINX directly should you
# wish to do so.
map $ssl_early_data $tls1_3_early_data {
    "~." $ssl_early_data;
    default "";
}

Save and close the file, then restart the Nginx service to enable the new configuration:

sudo systemctl restart nginx

For additional resources on installing Nginx, read the post below:

Step 7. Secure Discourse with Let’s Encrypt SSL.

First, install the Certbot client using the following command below:

sudo dnf install certbot python3-certbot-nginx

Next, get your SSL certificate with Let’s Encrypt by following these steps:

sudo certbot --nginx -d your-domain.com

Let’s Encrypt certificates have 90 days of validity, and it is highly advisable to renew the certificates before they expire. You can test automatic renewal for your certificates by running this command:

sudo certbot renew --dry-run

Step 8. Configure Firewall.

By default, Nginx listens on ports 80 and 443. If any firewall is installed and configured on your server, then you will need to allow both ports via firewalld. You can allow them with the following command:

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

You can verify by listing the current firewall settings:

sudo firewall-cmd --permanent --list-all

Step 9. Accessing Discourse Web Interface.

Once successfully installed, open your web browser and access the Discourse Web UI using the URL https://.your-domain.com. You should see the following page:

Install Discourse on Rocky Linux 9

Congratulations! You have successfully installed Discourse. Thanks for using this tutorial for installing the Discourse discussion platform on your Rocky Linux 9 system. For additional help or useful information, we recommend you check the official Discourse website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button