Discourse is a powerful open-source community discussion platform built using the Ruby language. It offers a flexible and customizable solution for creating forums, chat software, or mailing lists. In this step-by-step tutorial, we will guide you through the process of installing Discourse Forum with the Nginx server on a server running Rocky Linux 9. By the end of this tutorial, you will have a fully functional Discourse forum up and running.
Prerequisites
Before we begin, make sure you have the following prerequisites:
- A server running Rocky Linux 9 with at least 2GB RAM and 1 Core CPU.
- A non-root user with sudo privileges.
- A domain name (e.g., discourse.example.com) pointing to your server.
- Ensure that your server is up to date by running the following command:
sudo dnf update
Step 1 – Configure Firewall
The first step is to configure the firewall on your Rocky Linux server. By default, Rocky Linux uses Firewalld Firewall. You can check the status of the firewall by running the following command:
sudo firewall-cmd --state
If the firewall is not running, start it with the following command:
sudo systemctl start firewalld
To allow Discourse to function properly, you need to open HTTP and HTTPS ports. Run the following commands to open the necessary ports:
sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https
To apply the changes, reload the firewall:
sudo firewall-cmd --reload
Step 2 – Install Git
Git is a version control system that is required for installing Discourse. Install Git by running the following command:
sudo dnf install git -y
You can confirm the installation by checking the Git version:
git --version
Step 3 – Install Docker
Docker is a platform that allows you to package, distribute, and run applications in containers. Discourse uses Docker to simplify the installation process. To install Docker, follow these steps:
- Add the official Docker repository:
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- Install Docker:
sudo dnf install docker-ce docker-ce-cli containerd.io -y
- Enable and start the Docker service:
sudo systemctl enable docker --now
- Add your user to the Docker group to avoid using
sudo
every time you run Docker commands:
sudo usermod -aG docker $(whoami)
Note: You need to log out and log back in for the changes to take effect.
Step 4 – Download Discourse
In this step, we will clone the official Discourse Docker GitHub repository and prepare it for installation. Follow these steps:
- Clone the Discourse Docker repository to the
/var/discourse
directory:
sudo git clone https://github.com/discourse/discourse_docker.git /var/discourse
- Change to the Discourse directory:
cd /var/discourse
- Set the appropriate permissions:
sudo chmod 700 containers
Step 5 – Configure Discourse
Before installing Discourse, we need to configure some settings. Open the app.yml
file for editing:
sudo nano containers/app.yml
Set Domain
Set the DISCOURSE_HOSTNAME
variable to your domain name or IP address. If you don’t have a domain name, you can use an IP address instead.
DISCOURSE_HOSTNAME: 'discourse.example.com'
Configure Exposed Ports
Change the line "80:80"
to "8080:80"
. This will change the external HTTP port for Discourse to 8080 since we will use Nginx on port 80. Comment out the line "443:443"
since we will install SSL externally.
expose: - "8080:80" # http #- "443:443" # https
Configure Email IDs for the Administrator
Set the email addresses for your administrator account and the developer using the DISCOURSE_DEVELOPER_EMAILS
variable. Replace admin@example.com
and dev@example.com
with your actual email addresses.
DISCOURSE_DEVELOPER_EMAILS: 'admin@example.com,dev@example.com'
Configure SMTP Settings
Fill out the following variables with the appropriate values for your SMTP server. If you’re using a service like Gmail, you can find the SMTP settings in their documentation.
DISCOURSE_SMTP_ADDRESS: smtp.example.com
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: username@example.com
DISCOURSE_SMTP_PASSWORD: your_smtp_password
#DISCOURSE_SMTP_ENABLE_START_TLS: true # (optional, default true)
#DISCOURSE_SMTP_DOMAIN: discourse.example.com # (required by some providers)
#DISCOURSE_NOTIFICATION_EMAIL: noreply@example.com # (address to send notifications from)
Memory Settings (Optional)
If your server has limited RAM, you can configure the memory settings to optimize Discourse’s performance. Adjust the values of db_shared_buffers
and UNICORN_WORKERS
according to your server’s resources.
db_shared_buffers: '128MB' UNICORN_WORKERS: 2
Save the File
Save the changes to the app.yml
file by pressing Ctrl + X
, then Y
, and finally Enter
.
Step 6 – Install Discourse
In this step, we will bootstrap the Discourse container and start the Discourse application. Run the following commands:
sudo ./launcher bootstrap app sudo ./launcher start app
Step 7 – Install Nginx
Nginx is a popular web server that we will use as a reverse proxy for Discourse. Follow these steps to install Nginx:
- Add the official Nginx repository:
sudo dnf install -y dnf-utils sudo nano /etc/yum.repos.d/nginx.repo
Paste the following code into the file:
[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true
Save the file by pressing Ctrl + X
, then Y
, and finally Enter
.
- Install Nginx:
sudo dnf install nginx -y
- Enable and start the Nginx service:
sudo systemctl enable nginx --now
Step 8 – Install SSL
To secure your Discourse forum with SSL, we will use Let’s Encrypt, a free and widely trusted certificate authority. Follow these steps to install an SSL certificate:
- Install the Certbot tool:
sudo dnf install epel-release -y sudo dnf install certbot -y
- Generate the SSL certificate:
sudo certbot certonly --nginx --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m admin@example.com -d discourse.example.com
- Generate a Diffie-Hellman group certificate for added security:
sudo openssl dhparam-dsaparam -out /etc/ssl/certs/dhparam.pem 4096
This may take a few minutes to complete.
Step 9 – Configure Nginx
In this step, we will configure Nginx as a reverse proxy for Discourse. Open the configuration file for Discourse:
sudo nano /etc/nginx/conf.d/discourse.conf
Paste the following Nginx configuration code into the 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; # SSL ssl_certificate /etc/letsencrypt/live/discourse.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/discourse.example.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/discourse.example.com/chain.pem; ssl_session_timeout 5m; ssl_session_cache shared:SSL:10m; ssl_session_tickets off; ssl_protocols TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1; ssl_stapling on; ssl_stapling_verify on; ssl_dhparam /etc/ssl/certs/dhparam.pem; resolver 8.8.8.8; 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://discourse.example.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 ""; }
You can now access your Discourse forum by visiting the URL https://discourse.example.com
in your web browser. You will be greeted with the Discourse setup wizard.
Click the Register button to proceed with the installation. Enter your email address and choose a strong password for the administrator account. Click the Register button again to create the account.
If your SMTP settings are correct, you will receive an activation email. Follow the instructions in the email to activate your account.
Once activated, you will be redirected to the Discourse setup wizard. Fill in the required information, such as your forum name, description, and language preferences. Click Next to proceed to the next step.
On the Member Experience page, you can choose the options that best suit your forum’s needs. Click Next to continue.
Finally, you will be presented with the setup completion page. You can choose to configure more settings or jump right into using your forum. Feel free to explore the available options and customize your forum to your liking.
Congratulations! You have successfully installed Discourse Forum with Nginx on Rocky Linux 9. Your Discourse forum is now live and ready for use.
Step 11 – Discourse Commands
Discourse provides a set of useful commands that you can use to manage your forum from the command line. Here are some common commands:
- Activate Discourse Administrator from the command-line: If you didn’t receive the activation email, you can activate the administrator account from the command line. Enter the following commands:
cd /var/discourse sudo ./launcher enter app rails c
In the Rails console, locate the administrator account using the following command:
User.find_by_email("admin@example.com")
Replace “admin@example.com” with the email address of your administrator account. Once you find the account, run the following commands to activate it:
user.approved = true user.save EmailToken.confirm(user.email_tokens.first.token)
Type exit
twice to return to the command line.
- Backup Discourse: Discourse automatically backs up the database every 7 days by default. You can find the backup files in the
/var/discourse/shared/standalone/backups/default
directory. To manually trigger a backup, run the following command:
sudo ./launcher backup app
- Upgrade Discourse: To upgrade Discourse to the latest version, use the following commands:
cd /var/discourse sudo git pull sudo ./launcher rebuild app
This will update the Discourse installation with the latest files from GitHub and rebuild the Docker container.
- Stop Discourse: If you need to stop the Discourse application temporarily, use the following command:
sudo ./launcher stop app
- View Discourse Logs: You can view the Discourse logs by running the following command:
sudo ./launcher logs app
This will display the logs in the terminal.
Additionally, you can access detailed logs by visiting the URL https://discourse.example.com/logs/
in your web browser.
- View Rails / Unicorn Logs: Discourse uses Ruby on Rails and Unicorn as the web server. You can find the logs for Rails and Unicorn in the
/var/discourse/shared/standalone/log/rails
directory. Use the following command to access the logs:
ls /var/discourse/shared/standalone/log/rails
- View Nginx Logs: The Nginx logs for Discourse can be found in the
/var/discourse/shared/standalone/log/var-log/nginx
directory. Use the following command to access the logs:
ls /var/discourse/shared/standalone/log/var-log/nginx
- View Redis Logs: The Redis database logs can be found in the
/var/discourse/shared/standalone/log/var-log/redis
directory. Use the following command to access the logs:
ls /var/discourse/shared/standalone/log/var-log/redis
- View PostgreSQL Logs: The PostgreSQL database logs can be found in the
/var/discourse/shared/standalone/log/var-log/postgres
directory. Use the following command to access the logs:
ls /var/discourse/shared/standalone/log/var-log/postgres
Conclusion
Congratulations! You have successfully installed Discourse Forum with Nginx on Rocky Linux 9. Discourse provides a powerful platform for building online communities, and with the Nginx server acting as a reverse proxy, your forum is secured and ready for users to engage in meaningful discussions.
Discourse offers a wide range of features and customization options that allow you to tailor your forum to your specific needs. Whether you’re looking to create a support forum, a community-driven Q&A platform, or a vibrant discussion board, Discourse provides the tools to make it happen.
If you’re looking for reliable and scalable cloud hosting solutions, consider Shape.host’s Cloud VPS services. Shape.host offers high-performance virtual private servers with flexible configurations and robust security measures. With Shape.host, you can focus on building your online community while leaving the infrastructure management to the experts.
Start your Discourse journey today and experience the power of community collaboration with Shape.host’s cloud hosting solutions.