How to configure Discourse on Amazon Web services (AWS)

This guide will help you install the Discourse forum software on Ubuntu 18.04.4 LTS AWS EC2 instance with domain routing on AWS Route 53, SMTP on AWS SES and SSL certificate.


About Discourse : Discourse is an open source, feature rich  forum software built and managed by one of the most amazing teams on the internet today. Its also led by the great Jeff Atwood, this guy is a genius, he is also the co founder and developer of stackexchange.com, yes he is great. I highly recommend reading his blog ( Source to his blog ), which is well written and maintained for over 15 years !!! Yes very few blogs like his on the internet. 

Discourse allows people like me, to have a fully functional forum software, almost like Wordpress for web sites, and its awesome. Check out this website I made with discourse in just a couple of hours to track and have a conversation regarding the ongoing Covid-19 pandemic :  colloquium-19 .

 

Hardware Requirements for Discourse:

  • modern single core CPU, dual core recommended
  • 1 GB RAM minimum (with swap)
  • 64 bit Linux compatible with Docker
  • 10 GB disk space minimum

Software and Infrastructure Requirements:

  • Email address 
  • Amazon Web Services account 
  • SMTP details from Amazon SES
  • A domain name 

Github link : https://github.com/discourse/discourse


For this set up we will be using the following services on AWS:

1- AMAZON EC2 - Ubuntu 18.04.4 LTS instance.

2- AMAZON Simple Email Service ( SES) - SMTP 

3- Route 53 domain hosting and routing.

Along with AWS we shall use the following software packages through their command line interfaces:

1- Docker 

2- Discourse 


Step 1 : Configure Ubuntu on AWS EC2

1- Login to AWS - https://aws.amazon.com/ 


If you do not have an AWS account , you can sign up for a free trial and you will receive 750 hours of EC2 compute hours, 5 GB of S3 storage and many other great Amazon Web services for free, for the first 12 months.


2- Once you have created your account navigate to the EC2 option under compute, when you click on the services menu.



Once your in the Instances dashboard, at this point my suggestion would be to select the correct region in AWS. For this example and many of my projects I use North Virginia Usa east-1, due to a host of reasons like : cost , latency , & features,


 3- Choose the region which is closest to you or your target market, from the drop down menu on the top right. 



4- Click on the instances option on the left menu bar.



5- Now select the blue colored launch Instance button 



Next you will find your self in the AWS market place , here you can find the list of all images of the operating systems available on AWS EC2. 


6- In the top search bar type in Ubuntu , the first option that will be displayed is the ubuntu configuration we are looking for : Ubuntu Server 18.04 LTS (HVM). Select the instance by clicking the blue select button on the right.



Select the instance type, for a fully functional website with 1000's of users, you should use at least a t3a.small instance with 2 GB of RAM memory and 2 Virtual cpus, that can be utilized to handle heavier work loads. For this example we will use a t2.micro instance, which is eligible for the free tier usage by AWS, it has 1 GB RAM and 1 Vcpu , the bare minimum required to run Discourse.


7- Select t2.micro , with 1 GB Memory RAM and 1 Vcpu. 



8- Next click configure instance details , do not change anything here, click on Next:add storage.



Click add storage, the next part is important as AWS by default allocates only 8 GB of SSD memory to your instance. The required memory is at least 10 GB, not including back ups. My recommendation is to allocate at least 20 GB of memory to your EC2 instance, in case you will be utilizing heavy images and expect many users.

9- Allocate 20 GB of memory to your instance.


Next configure the security group, this is a very important step for AWS instances and is a major source of errors and wrong configuration problems, we have to make sure HTTPS, HTTP, SSH, and SMTP protocols are receivable by the instance.

 10- First name the security group, here we have name it as: launch-wizard-Discourse, then click add rule and add HTTPS, HTTP, SMTP, with default port numbers 443,80, and 25. SSH will be enabled by default , but my recommendation is to white list only your IP address, in the source section, to prevent any attacks.



11- Click review and launch, take the time to check your instance settings.


12- Click Launch.


At this point you will be prompted to select an existing authentication key or use a pre-existing one. For the sake of safety I would suggest you to create a new key pair, this is important as using the key is the only way you will be able to login to your instance.


13- Select create a new key pair from the drop down menu, and name the key pair, here we have used : Discourse_key1. Then click the download Key pair button and save the .PEM file in a secure location, your file will be name : Discourse_key1.pem.



14- Then click launch instances.




Instances should take any where between 2 minutes and 10 minutes to launch.


15- Navigate back to your instances in the EC2 menu, then select your new instance, give it a name for easier identification, here we have named it : Discourse_Tutorial. Note down the public DNS address ours is ec2-3-89-121-152.compute-1.amazonaws.com.
   



Step 2 : Configure SMTP on  Amazon Simple Email Service.


Configuring SMTP is a very important step, as Discourse will not be able to send the account activation email without it.


1- Navigate to the Amazon Simple email service ( SES) Dashboard. On the left menu click on SMTP settings.


Save the details:
Server Name: email-smtp.us-east-1.amazonaws.com
Port:25, 465 or 587
Use Transport Layer Security (TLS):Yes



2- Click on create my SMTP credentials and download the access key and username in the excel sheet format. Select the default IAM user name. Save the SMTP username and password safely. 


Next Verify the email address that shall be used to create the admin account on the discourse server.


3- Click on Email addresses on the left menu , and then click verify a new email address, enter your email address and you will
receive a verification mail from AWS , click on the link and now your email address is configured to interact with  Amazon SES SMTP.



Step 3 : Configure DNS and hosting on Amazon Route 53.


1- Navigate to Route 53 under the services menu in AWS and  purchase a domain name if you do not already have one, then click on Hosted zones button.



2- Select your  domain name and then click create record set , enter www in the Name section and choose A- IPV4 address in the Type drop down menu , then paste your public IPV 4 address in the Value section.


3- Click save record set.




Step 4 : Installing Discourse on Ubuntu 18.04.4 LTS ( AWS EC2 instance)


1- Login to your Ubuntu instance, open an SSH client (connect using PuTTY)


2- Locate your private key file (Discourse_key1.pem). The wizard automatically detects the key you used to launch the instance.


3- Your key must not be publicly view-able for SSH to work. Use this command if needed :


chmod 400 Discourse_key1.pem

4- Connect to your instance using its Public DNS,for our instance it will be :

ssh -i "Discourse_key1.pem" ubuntu@ec2-3-89-121-152.compute-1.amazonaws.com

5- We should always start by updating our installation package and make sure all system packages are up to date. Run the below commands:

sudo apt update 

sudo apt upgrade -y 

6- Install Docker, Run the below command to install the latest version of docker :


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

7- Check your docker version and running status with the below commands :

docker version


systemctl status  docker



Now we have docker installed , next we deploy discourse.


8- Create a directory /var/discourse 

sudo mkdir /var/discourse


9- Copy the official discourse Docker image into the newly created directory:

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

10- Run Discourse Set up tool to bootstrap Discourse.

sudo su -
cd /var/discourse

11- RUN
./discourse-setup

12- Provide the Domain name configured earlier , SMTP verified Email for admin , Smtp email server , SMTP port , SMTP user name , SMTP password , and an optional email for lets encrypt email for SSL certificate renewal. Your entries should look like the below.

Hostname for your Discourse? [discourse.example.com]: www.forgify.io // use activated domain email//
Email address for admin account(s)?: admin@example.com, // Use verified email //
SMTP server address? [smtp.example.com]:email-smtp.us-east-1.amazonaws.com
SMTP port? [587]: 465
SMTP user name? [user@example.com]: Aasdwfewfc@#$#@ **
SMTP password? [pa$$word]: BL3456gdsDFEFS
Optional email address for setting up Let's Encrypt? (ENTER to skip) [me@example.com]: admin@example.com

The details should be filled out extremely patiently and correctly, any mistake in the username and password will result in SMTP not being configured properly. 

All this data is stored in a file called containers/app.yml and every time you make a change , you will have to rebuild Discourse by running :

./launcher rebuild app

And then fill out the information  again.



13- Once the installation is complete , just enter your domain name into a web browser and you should get the discourse welcome screen.


14- Follow the installation wizard and you are ready to go .


Thanks , If this works for you , send me a thumbs up and upvote !!






Comments

thanks it worked really well
But the SES wont work on free tier
Hey @cooldude , please follow the link to understand how amazon SES works in free tier: https://aws.amazon.com/blogs/messaging-and-targ... The only hurdle you will face is to unblock your messaging limit, the first time you need to request it explicitly by clicking on the option to unblock your limit and make a request to increase your daily limit , also you have to provide a reason as to why you are requesting the limit increase. Else, raise a support ticket on amazon and they will help you out right away.
Nice instructions, but I was only able to make this work using SMTP Port 587.

Add a comment