Install Discourse on CentOS 7

Updated on June 23, 2024
Install Discourse on CentOS 7 header image

Introduction

Discourse is a new open-source forum solution which is simple, clean, and straightforward. It is implemented with Ruby on Rails, a Postgres database, and a Redis® server cache. This tutorial describes how to install Discourse on a Vultr VPS with CentOS 7.

Requirements

  • Vultr VPS with 1GB RAM minimum.
  • CentOS 7 x64 installed on the VPS.

Set up swap file

You must set up swap for a 1GB RAM VPS. If your VPS has more than 1GB RAM, you can skip this step. We will create a 2GB swapfile for 1GB RAM VPS.

  1. Create the swapfile.

     dd if=/dev/zero of=/swapfile bs=1M count=2048
     mkswap /swapfile
     chmod 600 /swapfile
  2. Edit fstab to add the swapfile into file systems table.

    Open fstab with vi:

     vi /etc/fstab

    Add the following line into the file:

     /swapfile       swap    swap    defaults      0       0
  3. Set the swap usage policy. Only use the swapfile when the system memory is low.

     sysctl -w vm.swappiness=10
     echo vm.swappiness = 10 | tee -a /etc/sysctl.conf
     sysctl vm.vfs_cache_pressure=60
     echo vm.vfs_cache_pressure = 60 | tee -a /etc/sysctl.conf
  4. Enable the swapfile.

     mount -a
     swapon -a
  5. Check the swapfile state.

    swapon -s

    If the swapfile has been enabled, you will see the following information.

    Filename                    Type    Size	Used	Priority
    /swapfile                  file     2097148	0      	-1

Install Docker

Run the command below to install Docker on CentOS 7.

yum install docker

If you have disabled SELinux, you'd better disable it in docker also.

vi /etc/sysconfig/docker

Comment out line 4.

#OPTIONS='--selinux-enabled'

Start the docker service.

systemctl start docker
systemctl enable docker

Please note that if you restart firewalld, you will need restart docker also. Because firewalld will remove the docker chain from iptables when it's restarted.

Install Discourse

Create a folder named discourse under /var and clone the Discourse repository.

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

Go to the discourse folder.

cd /var/discourse

Copy the Discourse configuration template file into the containers folder.

cp samples/standalone.yml containers/app.yml

Configure Discourse

  1. Open the app.yml with vi.

      vi containers/app.yml
  2. If you are using a 1GB VPS, set the db shared buffer as 128MB in app.yml.

     db_shared_buffers: "128MB"
  3. Change UNICORN_WORKERS to 2 for a 1GB RAM instance.

     ## With 2GB we recommend 3-4 workers, with 1GB only 2
     UNICORN_WORKERS: 2
  4. Set your email address for the admin account. You will need this email to register the admin account on your Discourse forum.

     DISCOURSE_DEVELOPER_EMAILS: 'you@youremail.com'
  5. Set the domain name for Discourse. For example, we set it as discourse.example.com, that means it would be accessible at the URL http://discourse.example.com/.

     ## TODO: The domain name this Discourse instance will respond to
     DISCOURSE_HOSTNAME: 'discourse.example.com'
  6. Configure your mail server for Discourse.

    If your mail server is on the same server with Discourse, configure it as follows.

     DISCOURSE_SMTP_ADDRESS: smtp.example.com                               # (mandatory)
     DISCOURSE_SMTP_PORT: 587                                                              # (optional)
     DISCOURSE_SMTP_USER_NAME: YOUR_EMAIL_ACCOUNT                # (optional)
     DISCOURSE_SMTP_PASSWORD: YOURPASSWORD                             # (optional)
     DISCOURSE_SMTP_ENABLE_START_TLS: flase                                    # (optional, default true)
     DISCOURSE_SMTP_OPENSSL_VERIFY_MODE: none

    If you use a remote SMTP server, please edit the app.yml as follows.

     DISCOURSE_SMTP_ADDRESS: smtp.example.com                               # (mandatory)
     DISCOURSE_SMTP_PORT: 587                                                              # (optional)
     DISCOURSE_SMTP_USER_NAME: your@example.com                          # (optional)
     DISCOURSE_SMTP_PASSWORD: YOURPASSWORD                             # (optional)
     DISCOURSE_SMTP_ENABLE_START_TLS: true                                     # (optional, default true)
  7. Save and exit app.yml.

Bootstrap and start Discourse

Run the command below to bootstrap Discourse.

./launcher bootstrap app

After the bootstrapping process has completed, start Discourse.

./launcher start app

Open Discourse in your browser

On your client PC, input the domain name that you configured for Discourse in app.yml. You will see your own instance of Discourse.

Troubleshooting

  • By default, Docker will listen on port 80. If the port 80 has been used by Nginx or Apache already, you need move that service to another port; or change Docker to another port. For example, change "80:80" to "8080:80" in app.yml to make Docker listen on port 8080.
  • On the 1GB RAM VPS, it may fail to update the Discourse to the new version, and you will see a "502 Bad Gateway" when accessing Discourse. The simple solution for this issue is to run ./launcher rebuild app to rebuild your Discourse instance.