I wrote this tutorial in July 2018 for Alibabacloud Techshare. You can find the edited copy of this tutorial on Alibaba cloud blog. Publishing my original copy here.
Discourse is a modern style free and open source forum system that runs on Ruby on rails, uses PostgreSQL as database system and redis cache. It is used by many top companies to develop communities around their products and to provide support.
For installation Discourse team recommends a VPS or dedicated server with 2 GB RAM, although for smaller communities it can be installed on server with 1GB RAM with swap enabled . You also need SMTP for sending email and CDN for delivering static content.
You can get all these services at Alibaba Cloud. Register with Alibaba Cloud to get $300 credit to check out these and many more services.
In this guide we will be installing Discourse on Alibaba Cloud’s Elastic Compute Service (ECS) and use Directmail for sending emails and Cloud CDN for static content delivery.
Prerequisites
For this tutorial we will be needing:
- ECS instance with at least 2GB RAM and 1 vCPU
- A domain name or subdomain that resolve to your ECS instance
- Cloud CDN setup to speed up our forum
- Directmail SMTP credentials for sending email from our forum
We will need to setup all these before beginning the actual installation because discourse installer will ask for these information at the beginning of setup process.
I. Creating the ECS instance
Although if you already have a VPS or dedicated server with any other service you can use it to install Discourse but I highly recommend using ECS to reduce the latency between server and Directmail as well as CDN.
To create an ECS instance login to your Alibaba Cloud console by click here. This link will take you directly to instance selection page.
You can find the steps to creating new instance in ECS quick start guide.
This is the configuration we need in the server to install Discourse:
- An instance with 1 or more vCPU depending on your choice and at least 2GB RAM.
- For Image select Ubuntu 16.06 64 bit version.
- In storage section select Ultra Cloud Disk 40 Gib.
- Open Ports 80(http), 443(https) and 22(SSH) in security group section on networking page.
Note the IP address of the instance as we will be needing it in next steps.
II. Setting Domain name
We are doing this step early because DNS propagation takes some time. We want it propagated before we run the installer as lets encrypt require it to generate SSL certificate.
For this step you only have to add an A record in DNS configutaion of your domain that point your domain or subdomain to ECS instance’s IP address.
This is what you need to add:
Record type: A
Name: forum.example.com
Value: your.server.ip.address
(eg. 192.168.1.1. You will get this in you ECS console)
This is how it looks in my DNS settings:
III. Setting up CloudCDN
This I am describing in detail as these are few setting we have to do to make it work with Discourse. For offilcial CloudCDN documentation you can go to the CloudCDN quickstart guide.
We will need to perform four main steps here:
1. Adding the CDN domain
Head over to CDN console by clicking here.
Click on the CDN Domain Name List
under the CDN menu.
Click on the Add domain
button on right side.
You will see a form to setup your CDN domain and origin.
In the CDN Domain
field enter a subdomain of your domain name. For example cdn.example.com
In Business type select Images and Small file
.
In Origin Site Type select Origin Site Domain Name
.
Enter the domain name you will be using for your forum in the field that appears.
In Port
field select Port 443
as Discourse installer will install Letsencrypt SSL certificate and serve your forum on port 443.
In Accelerating Region
select Global Acceleration
if you want to use POPs in Mainland China as well as rest of the world or you can choose Overseas Acceleration(non-chinese mainland)
if you want to use only POPs putside China. To use only Chinese POPs you should select Chinese Mainland
from the menu.
This is how it should look
Click on Next
Button.
Your CDN will be configured in few minutes and you will be given an unique URL. You will have to create an CNAME in your domain’s DNS setting pointing yo this url.
2. Installing the SSL certificate for CDN
We need to setup SSL certificate for the CDN subdomain. If you already have the certificate you can install it and if not you can either buy it from Alibabacloud or can find free SSL certificate by a simple web search.
To install the certificate click on the manage
link in front of the url in cdn url list and then click on the pen icon
in front of HTTPS Secure Acceleration
Turn on the Certificate Status
switch.
In Select Certificate
field choose Custom Upload
.
Enter a name of your choice in Certificate Name
field.
Enter Certificate content
and Private key
in marked textboxes. These are provided to you by the certificate provider.
In Redirect Type
click on the radio button that says HTTP -> HTTPS
.
It should look like this
Click OK
to save.
3. Setting Back-to-source Host
This setting is required so your CDN does not do a 301 redirect to your origin server.
Click pen icon
in front of Back-to-source Host
under Basic Configuration
section.
A overlay window will open.
Switch on the button.
From the Type
dropdown menu select domain name of your origin.
It should look like this
Click on OK
button to save.
4. Setting the CORS HTTP header
Now click on the Set HTTP Header
on side menu.
Click on Add HTTP header
button on right side
A window will open.
Select Access control allow origin
from the dropdown menu. And in value add *
After saving it should look like this
Note the CDN URL, we will be needing it later.
This is it for the CDN setup.
IV. Get Directmail SMTP credentials
Directmail is email service by Alibabacloud and it is one of the cheapest and most reliable service available.
Note: Email setting is the most common step where most of the new users break their forum and have to rebuild it. So be careful.
Head over to the Directmail console by clicking here.
If you have not activated it before it will ask you to do so.
For detailed documentation you can read the Directmail documentation but I will give you a short version here because there are few things we need to do to make it work with discourse.
You need to setup Directmail in 3 steps:
1. Add sender domain
This will be the domain from where the email will be send. You need to use your forum domain as it is important. For example forum.example.com
.
Click on the New Domain
button on the top right. A popup window will open.
Enter your forum’s domain in the the Domain
field and click OK
button.
A domain verification is needed to activate it.
Click on the configure
link in front of your domain.
You will be presented with the DNS configuration data. You need to add these in enties DNS panel of your domain.
After you have added the DNS records to your domain’s configuration click on the Confirm Changes
button at the bottom.
Now click on the verify
link in front of your domain.
You will be able to send mails only after the domain status changes to Available
. If the it fails to verify even after correct configuration wait for a while then verify again, sometime DNS changes takes time to take effect.
2. Add sender email address
Click on the Sender Addresses in the left menu.
Click on Create Sender Address
button on the top right.
A Overlay window will open where you need to enter the data.
Fill all the fields like this to setup sender email:
Email Domains
: select your forum’s domain from dropdown menu.
Account
: noreply (This is important to put only noreply
as account or authentication will fail and your forum will not ne able to send email.
Reply-to Address
: Any email address you like where you will like to receive replies.
Mail Type
: Triggered Emails.
It should look like this
Press OK
to create sender address.
3. Set SMTP password
Click on the Set SMTP password
link in front of the sender email address you set in previous step.
A overlay window will open where you can set your password.
Read the instructions carefully as it requires mix of lower case upper case letter and number. Use atleast 2 different uppercase letter, 2 different lowercase letters and 2 different digits for your password.
Note the sender email address and SMTP password. It will be needed while running the Discourse installer. You will also need SMTP service address that you can find here. Choose the one for the region you set your directmail account in.
V. Running the Discourse Installer
Discouse team have made it quite easy to install discourse. You only have to install docker first and download and run the installer. After few minutes and couple of question you will get your new discourse forum ready.
Login to you server via SSH
ssh [email protected]
*Replace 192.168.1.1 with your IP address.
After successful login run the following command to update your system first.
sudo apt-get update && apt-get upgrade -y
All the steps will be run as root user so run this command first
sudo -s
Install Docker
Discourse forum runs inside docker container so we will first install the latest docker
wget -qO- https://get.docker.com/ | sh
Above command will install the docker in your server.
Install GIT
apt-get install git
Download Discourse installer
Create a directory to install discourse
mkdir /var/discourse
Clone discourse doscker image inside this folder
git clone https://github.com/discourse/discourse_docker.git /var/discourse
Change to to this directory
cd /var/discourse
Run Discourse installer
Initiate setup script
./discourse-setup
Discourse will create a swap space first and then you will be asked for these information
Hostname for your Discourse? [discourse.example.com]: Email address for admin account(s)? [[email protected],[email protected]]: SMTP server address? [smtp.example.com]: SMTP port? [587]: SMTP user name? [[email protected]]: SMTP password? [pa$word]: Let's Encrypt account email? (ENTER to skip) [[email protected]]:
Let me explain these
- Hostname for your discourse: This is the domain or subdomain that you want to use with your forum. We set it in the Step II while adding A record in your domain’s DNS.
- Email address for admin accounts: Here you enter the email address of the admin account of your forum. You can add multiple admin email separated my comma(,). this is not your SMTP sender address.
- SMTP server address: This is the address of the SMTP server of Directmail. You can find it on this page. Choose the one for the region where you have created your Directmail account. You can see your region at the top of the Directmail console.
- SMTP port: Enter 80 here as this is the port that Directmail uses for SMTP connection.
- SMTP user name: Here you enter the sender email address we created in Step V.
- SMTP password: Enter the SMTP password we set in step V.
- Let’s Encrypt account email: This is the email address that let’s encrypt uses to generate SSL certificate for your domain and send notifications regarding expiration and renewal failure. You can skip it but I suggest you do enter an email address you check regularly. Also make sure your DNS has been propagated before running the installer as it is important for generating let’s encrypt certificate.
After you have entered the information setup will show all the information you gave on the screen for review and ask for confirmation. Check it carefully and if all is correct press ENTER
key. If you need to change something type n
and then ENTER
.
After confirmation will take around 10 minutes to setup everything.
After the setup finishes you can see your forum in the browser by visiting the URL you entered.
At this stage although your forum is working but it is not currently using CloudCDN. We will set up this now.
VI. Setting up CloudCDN
Go to the discourse directory if you are not already into it.
cd /var/discourse
Open the app.yml file in nano for editing
nano containers/app.yml
Scroll down until you find this line.
#DISCOURSE_CDN_URL: //discourse-cdn.example.com
And paste this line right below it. Make sure you keep the same indentation as line above.
DISCOURSE_CDN_URL: //cdn.example.com
*replace the url with CDN url we set in the step IV.
Press control+O
and ENTER
to save changes.
Press control+X
and then ENTER
to exit nano.
Now rebuild the app
./launcher rebuild app
Rebuild process will take about 10 minutes.
Your forum will now use CloudCDN to serve static content.
Now visit enter your forum’s URL and you will be greetied with this message
Click on the register button and fill all the fields as required to create administrator account for the forum. Forum will send you email to confirm your email address. If you do not get the email review your Directmail settings and make sure you have followed the tutorial carefully. If you need to change the SMTP setting in forum you can run the setup again by using this command inside discourse directory.
./discourse-setup
You will be asked all the information again and installer will also show you all the information you gave earlier.
After confirmation of your email go through the initial Discourse setup and you will be soon see your forum’s homepage.
Enjoy your new Discourse forum 🙂
Conclusion
You can install Discourse forum software quite easily on Alibabcloud’s infrastructure. You don’t have to buy from multiple providers as you get all the required services like server, SMTP and CDN from Alibabacloud and most of them are cheaper but more reliable than other providers. If you have not signed up yet register and get $300 credit to check out the Alibabacloud services.