Discourse is a well-known open-source forum platform written in Ruby, known for being clean and simple.

One forum I love browsing is Koushui Loushi, which is built on Discuz, and its UI is stuck in the Stone Age. Its many user-hostile features also annoyed me. So on a whim, I decided to build my own forum. Starting from scratch, I bought a domain, bought a server, set up the software, and tested it. In about an afternoon, I built a forum about Future Sci-Tech City. Enough talk; here's the result.

https://zjfuture.us. The official website of the Future Sci-Tech City Overseas High-Level Talent Innovation Park is zjfuture.gov.cn. I picked a similar domain, meaning: us, the citizens living in Future Sci-Tech City.

zjfuture-demo

What I Used

  • Domain: bought from name.com for $3
  • Server: Linode, $10/month. I chose Linode for its stability and reputation, and because it recently upgraded to 2 GB of RAM for its 13th anniversary. For Rails apps, more memory is definitely better
  • Email provider: Mailgun, free
  • Logo: made in Sketch

Installation

The official installation guide is very detailed and clear: Set up Discourse in the cloud in under 30 minutes. If you follow the steps, it should work. Here's a quick summary

Install Git and Docker

Discourse is easy to install, with no need to wrestle with Ruby or server setup, because it's packaged in Docker. How thoughtful is that? Installing both takes just one command

wget -qO- https://get.docker.com/ | sh

Install Discourse

Create the /var/discourse directory and run these commands in order

1
2
3
mkdir /var/discourse
git clone https://github.com/discourse/discourse_docker.git /var/discourse
cd /var/discourse

Configure the Mail Server

Go to /var/discourse and run the ./discourse-setup script to configure email. Before doing this, sign up for a Mailgun account, then add the MX, TXT, and other records with your domain's DNS provider. Mailgun's docs are very detailed, so just follow along. After running the script

1
2
3
4
5
6
Hostname for your Discourse? [discourse.example.com]:
Email address for admin account? [me@example.com]:
SMTP server address? [smtp.example.com]:
SMTP user name? [postmaster@discourse.example.com]:
SMTP port [587]:
SMTP password? []:

Here's what the settings mean

  • hostname: the forum's domain
  • Admin email address: your own email
  • SMTP server address: smtp.mailgun.com
  • Username: xxx@hostname
  • Port: the default, 587, is fine. For SSL/TLS, use 465
  • Password: your password

Mailgun settings are shown below
maigun-config

Don't worry if you make a mistake while running the script. Open /var/discourse/containers/app.yam to edit it again. When you're done, run ./launch rebuild app to initialize the container. Then open the domain or IP to access it.

Configure app.yml

app.yml has several main sections: templates, expose, params, env, hooks, and run.
In templates, add one line to the defaults for better localization support

1
2
3
4
5
6
templates:
- "templates/postgres.template.yml"
- "templates/redis.template.yml"
- "templates/web.template.yml"
- "templates/web.ratelimited.template.yml"
- "templates/web.china.template.yml"# Add this line

Configure ports in expose: 80 for HTTP, 443 for HTTPS. Both are open by default.
Configure the domain and email settings in env

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
LANG: zh_CN # Language, set to Chinese
# DISCOURSE_DEFAULT_LOCALE: en
## How many concurrent web requests are supported? Depends on memory and CPU cores.
## will be set automatically by bootstrap based on detected CPUs, or you can override
UNICORN_WORKERS: 4
## TODO: The domain name this Discourse instance will respond to
DISCOURSE_HOSTNAME: zjfuture.us # Domain
## Uncomment if you want the container to be started with the same
## hostname (-h option) as specified above (default "$hostname-$config")
#DOCKER_USE_HOSTNAME: true
## TODO: List of comma delimited emails that will be made admin and developer
## on initial signup example 'user1@example.com,user2@example.com'
DISCOURSE_DEVELOPER_EMAILS: 'beeponky@gmail.com'
## TODO: The SMTP mail server used to validate new accounts and send notifications
DISCOURSE_SMTP_ADDRESS: smtp.mailgun.org
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: xxx@zjfuture.us
DISCOURSE_SMTP_PASSWORD: "xxx"
#DISCOURSE_SMTP_ENABLE_START_TLS: true # (optional, default true)

Create an Admin Account

Most settings are configured by the admin in the dashboard, so set up the admin first. Connect to the server, run cd /var/discourse, then ./launch enter app to enter the Rails app in the Docker container, and run
rake admin:create This same command creates a new admin, resets an admin password, or gives admin rights to an existing account.
Note: Create Admin Account from Console

Set Up HTTPS with Let’s Encrypt

I've never seen an app where HTTPS was this easy to set up. See this tutorial: Let’s Encrypt. When you're done, go to Settings > Security > use https to force HTTPS.

At this point, you have a clean, simple forum. What's left is configuration, customization, and community management.