Tutorial

How To Install Discourse on Ubuntu 14.04

Published on September 10, 2014
How To Install Discourse on Ubuntu 14.04
Not using Ubuntu 14.04?Choose a different version or distribution.
Ubuntu 14.04

This tutorial is out of date and no longer maintained.

Warning: This article is out of date and no longer works. Please read the updated Discourse article instead.

An Article from Discourse

Introduction

Discourse is an open source discussion platform built for the next decade of the Internet. We’ll walk through all of the steps required to get Discourse running on your DigitalOcean Droplet.

Prerequisites

Before we get started, there are a few things we need to set up first:

  • Ubuntu 14.04 Droplet (64 bit) with a minimum of 2 GB of RAM. If you need help with this part, this tutorial will get you started.

    Discourse recommends 1 GB of RAM for small communities and 2 GB of RAM for larger communities. It also requires a swap file if you are using 1 GB of RAM. Although swap is generally recommended for systems utilizing traditional spinning hard drives, using swap with SSDs can cause issues with hardware degradation over time. Due to this consideration, we do not recommend enabling swap on DigitalOcean or any other provider that utilizes SSD storage. Doing so can impact the reliability of the underlying hardware for you and your neighbors. Hence, we recommend a minimum of 2 GB of RAM to run Discourse on a DigitalOcean Droplet. Refer to How To Add Swap on Ubuntu 14.04 for details on using swap.

    If you need to improve the performance of your server, we recommend upgrading your Droplet. This will lead to better results in general and will decrease the likelihood of contributing to hardware issues that can affect your service.

  • You can use an IP address as your domain for testing, but for a production server, you should have a domain that resolves to your Droplet. This tutorial can help.

All the commands in this tutorial should be run as a non-root user. If root access is required for the command, it will be preceded by sudo. Initial Server Setup with Ubuntu 14.04 explains how to add users and give them sudo access.

Step 1 — Install Git

In this section we will install Git to download the Discourse source files. Git is an open source distributed version control and source code management system.

Before we get started, it is highly recommend to make sure that your system is up to date. SSH into your Droplet as the root user:

  1. ssh sammy@your-server-ip

Execute the following commands on your Droplet to update the system:

  1. sudo apt-get update
  2. sudo apt-get upgrade

Once that is complete, install Git by running following command:

  1. sudo apt-get install git

Step 2 — Install Docker

In this section we will install Docker so that Discourse will have an isolated environment in which to run. Docker is an open source project that can pack, ship, and run any application in a lightweight container. For more introductory information about Docker, please see this tutorial.

Docker provides a public script to get Docker installed:

  1. wget -qO- https://get.docker.io/ | sh

You need to add your non-root user to the docker group to be able to run a Docker container as this user:

  1. sudo usermod -aG docker sammy

You also have to log out and log back in as that user to enable the change:

  1. exit
  2. su - sammy

Step 3 — Download Discourse

In this section we will download Discourse.

Create a /var/discourse folder, where all the Discourse-related files will reside:

  1. sudo mkdir /var/discourse

Clone the official Discourse Docker Image into this /var/discourse folder:

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

Step 4 — Configure Discourse

In this section we will configure your initial Discourse settings.

Switch to the /var/discourse directory:

  1. cd /var/discourse

Copy the samples/standalone.yml file into the containers folder as app.yml:

  1. sudo cp samples/standalone.yml containers/app.yml

Edit the Discourse configuration in the app.yml file:

  1. sudo nano containers/app.yml

The configuration file will open in the nano text editor.

Locate the env section and update it with your custom email, domain, and SMTP server information, as shown below. The individual lines are explained after the example block:

app.yml
...
env:
  LANG: en_US.UTF-8
  ## TODO: How many concurrent web requests are supported?
  ## With 2GB we recommend 3-4 workers, with 1GB only 2
  #UNICORN_WORKERS: 3
  ##
  ## 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: 'me@example.com'
  ##
  ## TODO: The domain name this Discourse instance will respond to
  DISCOURSE_HOSTNAME: 'discourse.example.com'
  ##
  ## TODO: The mailserver this Discourse instance will use
  DISCOURSE_SMTP_ADDRESS: smtp.mandrillapp.com         # (mandatory)
  DISCOURSE_SMTP_PORT: 587                        # (optional)
  DISCOURSE_SMTP_USER_NAME: login@example.com      # (optional)
  DISCOURSE_SMTP_PASSWORD: 9gM5oAw5pBB50KvjcwAmpQ               # (optional)
  ##
  ## The CDN address for this Discourse instance (configured to pull)
  #DISCOURSE_CDN_URL: //discourse-cdn.example.com
  ...

Here are the individual lines that need to be changed:

  1. Set Admin Email

Choose the email address that you want to use for the Discourse admin account. It can be totally unrelated to your Discourse domain and can be any email address you find convenient. Set this email address in the DISCOURSE_DEVELOPER_EMAILS line. This email address will be made the Discourse admin by default, once a user registers with that email. You’ll need this email address later when you set up Discourse from its web control panel.

DISCOURSE_DEVELOPER_EMAILS: 'me@example.com'

Replace me@example.com with your email.

Developer Email setup is required for creating and activating your initial administrator account.

  1. Set Domain

Set DISCOURSE_HOSTNAME to discourse.example.com. This means you want your Discourse forum to be available at http://discourse.example.com/. You can use an IP address here instead if you don’t have a domain pointing to your server yet. Only one domain (or IP) can be listed here.

DISCOURSE_HOSTNAME: 'discourse.example.com'

Replace discourse.example.com with your domain. A hostname is required to access your Discourse instance from the web.

  1. Set Mail Credentials

We recommend Mandrill for your SMTP mail server. Get your SMTP credentials from Mandrill.

Enter your SMTP credentials in the lines for DISCOURSE_SMTP_ADDRESS, DISCOURSE_SMTP_PORT, DISCOURSE_SMTP_USER_NAME, and DISCOURSE_SMTP_PASSWORD. (Be sure you remove the comment # character from the beginnings of these lines as necessary.)

DISCOURSE_SMTP_ADDRESS: smtp.mandrillapp.com         # (mandatory)
DISCOURSE_SMTP_PORT: 587                        # (optional)
DISCOURSE_SMTP_USER_NAME: login@example.com      # (optional)
DISCOURSE_SMTP_PASSWORD: 9gM5oAw5pBB50KvjcwAmpQ               # (optional)

The SMTP settings are required to send mail from your Discourse instance; for example, to send registration emails, password reset emails, reply notifications, etc.

Having trouble setting up mail credentials? See the Discourse Email Troubleshooting guide.

Setting up mail credentials is required, or else you will not be able to bootstrap your Discourse instance. The credentials must be correct, or else you will not be able to register users (including the admin user) for the forum.

  1. Optional: Tune Memory Settings (preferred for 1 GB Droplet)

Also in the env section of the configuration file, set db_shared_buffers to 128MB and UNICORN_WORKERS to 2 so you have more memory room.

db_shared_buffers: "128MB"

and

UNICORN_WORKERS: 2

Tuning these memory settings will optimize Discourse performance on a 1 GB Droplet.

NOTE: The above changes are mandatory and should not be skipped, or else you will have a broken Discourse forum.

Save the app.yml file, and exit the text editor.

Step 5 — Bootstrap Discourse

In this section we will bootstrap Discourse.

First, we need to make sure that Docker can access all of the outside resources it needs. Open the Docker settings file /etc/default/docker:

  1. sudo nano /etc/default/docker

Uncomment the DOCKER_OPTS line so Docker uses Google’s DNS:

/etc/default/docker
...

# Use DOCKER_OPTS to modify the daemon startup options.
DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"

...

Restart Docker to apply the new settings:

  1. sudo service docker restart

Note: If you don’t change Docker’s DNS settings before running the bootstrap command, you may get an error like “fatal: unable to access ‘https://github.com/SamSaffron/pups.git/’: Could not resolve host: github.com”.

Now use the bootstrap process to build Discourse and initialize it with all the settings you configured in the previous section. This also starts the Docker container. You must be in the /var/discourse directory:

  1. cd /var/discourse

Bootstrap Discourse:

  1. sudo ./launcher bootstrap app

This command will take about 8 minutes to run while it configures your Discourse environment. (Early in this process you will be asked to generate a SSH key; press Y to accept.)

After the bootstrap process completes, start Discourse:

  1. sudo ./launcher start app

Congratulations! You now have your very own Discourse instance!

Step 6 — Access Discourse

Visit the domain or IP address (that you set for the Discourse hostname previously) in your web browser to view the default Discourse web page.

discourse

If you receive a 502 Bad Gateway error, try waiting a minute or two and then refreshing so Discourse can finish starting.

Step 7 — Sign Up and Create Admin Account

Use the Sign Up button at the top right of the page to register a new Discourse account. You should use the email address you provided in the DISCOURSE_DEVELOPER_EMAILS setting previously. Once you confirm your account, that account will automatically be granted admin privileges.

sign_up

Once you sign up and log in, you should see the Staff topics and the Admin Quick Start Guide. It contains the next steps for further configuring and customizing your Discourse installation.

You can access the admin dashboard by visting /admin.

dash

If you don’t get any email from signing up, and are unable to register a new admin account, please see the Discourse email troubleshooting checklist.

If you are still unable to register a new admin account via email, see the Create Admin Account from Console walkthrough, but please note that you will have a broken site until you get normal SMTP email working.

That’s it! You can now let users sign up and start managing your Discourse forum.

Post-Installation Upgrade

To upgrade Discourse to the latest version, visit /admin/upgrade and follow the instructions.

upgrade

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


About the authors


Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
10 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

I followed everything to the end. Everything looks fine except emails don’t work at all so Discourse won’t start :( Start-up emails never get to my inbox. They don’t even show up in Mandrill. That make me sad…

Step 5.4 - You write that db_shared_buffers should be 128MB but the snippet is 256MB - Which should I choose?

Also required 64 BIT ubuntu; 32bit can not work due to Docker.

I follow this instruction but it didn’t work. Why don’t I see where the configuration of database?

I tried the same instructions twice and stuck at the admin verification email. Earlier I tried twice with the one-click install as well. In both the cases I am stuck at the admin verification email. Discourse is not able to send the verification email appears to be the issue. There is definitely something missing here which most of the howto install Discourse on DigitalOcean guides are missing. There are 2 possibilities as mentioned below:

  1. SMTP ports are blocked by DigitalOcean
  2. MTA (mail transfer agent) needs to be installed along with Discourse

Can someone mention precise installation steps.

Just ran the Pre-compile and got an error:

/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:60:in `block (3 levels) in define'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/rake/sprocketstask.rb:146:in `with_logger'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:59:in `block (2 levels) in define'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
I, [2015-10-19T15:52:01.065966 #44]  INFO -- : Purging temp files
Bundling assets

I, [2015-10-19T15:52:01.069317 #44]  INFO -- : Terminating async processes
I, [2015-10-19T15:52:01.071566 #44]  INFO -- : Sending INT to HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/9.3/bin/postmaster -D /etc/postgresql/9.3/main pid: 114
I, [2015-10-19T15:52:01.072185 #44]  INFO -- : Sending TERM to exec chpst -u redis -U redis /usr/bin/redis-server /etc/redis/redis.conf pid: 242
2015-10-19 15:52:01 UTC [114-2] LOG:  received fast shutdown request
2015-10-19 15:52:01 UTC [114-3] LOG:  aborting any active transactions
2015-10-19 15:52:01 UTC [121-2] LOG:  autovacuum launcher shutting down
2015-10-19 15:52:01 UTC [118-1] LOG:  shutting down
242:signal-handler (1445269921) Received SIGTERM scheduling shutdown...
242:M 19 Oct 15:52:01.125 # User requested shutdown...
242:M 19 Oct 15:52:01.126 * Saving the final RDB snapshot before exiting.
242:M 19 Oct 15:52:01.158 * DB saved on disk
242:M 19 Oct 15:52:01.158 # Redis is now ready to exit, bye bye...
2015-10-19 15:52:01 UTC [118-2] LOG:  database system is shut down


FAILED
--------------------
RuntimeError: cd /var/www/discourse && su discourse -c 'bundle exec rake assets:precompile' failed with return #<Process::Status: pid 4584 exit 1>
Location of failure: /pups/lib/pups/exec_command.rb:105:in `spawn'
exec failed with the params {"cd"=>"$home", "hook"=>"bundle_exec", "cmd"=>["su discourse -c 'bundle install --deployment --verbose --without test --without development'", "su discourse -c 'bundle exec rake db:migrate'", "su discourse -c 'bundle exec rake assets:precompile'"]}
16677208de51e0ad9ddf8f9bae8501797a2df43cfc30bccf9b15985ebcffad96
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one

Is it possible to install with 512MB memory and runs a website too ?

Great guide!

I followed these step-by-step instructions and was able to deploy Discourse on a 1GB droplet. The only thing I did that was not indicated in the guide was to select a 64 bit Ubuntu as mentioned by user H4U.

My Discourse forum is up and running. Now on to customizing it.

I have installed from automatic installation for 3 times, but: Everything looks fine, but the emails don’t work. I can´t use Discourse. What´s the problem?

for me, it doesnt work just out of box, because it says “cannot start container listen tcp 0.0.0.0:80 bind: address already in use” so i am not sure how to proceed. i understand it is already used by nginx… but dont know how to manage it.

ok i changed port to 8081:80

now how to set nginx to forward domain:80 to this (:8081)

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel