Installing Discourse on Ubuntu

You have a number of options when installing Discourse on Ubuntu - these include doing so manually or installing through Cloud 66 EasyDeploy.

Depending on your configuration, a manual installation of Discourse can take up to a few days. Deploying through Cloud 66 on the other hand takes up to an hour for the initial deploy, and up to five minutes for subsequent deployments.

This post will take you through each option.

Option 1: Deploying with Cloud 66

Deploying with Cloud 66 consists of five simple steps:

1. Create an account on Cloud 66.

2. Click here to auto-fill your new stack page. 

3. Once the code has been analyzed, you need to specify environment variables for your deployment, as seen in the image below:


These are the environment variables you need to set: 

  • HOST_NAME' - the domain hosting your site (required)
  • SMTP_ADDRESS' - your SMTP provider address (optional)
  • SMTP_PORT' - your SMTP provider port (optional)
  • SMTP_DOMAIN' - the domain you send emails from (optional)
  • SMTP_USERNAME' - your SMTP username (optional)
  • SMTP_PASSWORD' - your SMTP password (optional)

To send emails, you can easily set up SMTP on your server, or use a service like Sendgrid or Mailchimp.

4. Next, choose where you’d like to deploy Discourse, the region and server size. You can also choose if you’d like to deploy to separate web, database and Redis servers.

5. Once you’re happy with your configuration, simply click ‘deploy’, and sit back and relax while we deploy Discourse for you.

Option 2: Manual Installation

1. Install Ubuntu Server 12.04 LTS with the package groups:

Yes, you can in theory pick the distro of your choice, but to keep this guide sane, we’re picking one, and it’s Ubuntu. Feel free to substitute the distro of your choice, the steps are mostly the same.


  • Basic Ubuntu server
  • OpenSSH server
  • Mail server
  • PostgreSQL database (9.1+)

You may be working on an already-installed or automatically deployed system, in which case you can install them afterward:

# Run these commands as your normal login (e.g. "michael")
sudo apt-get update && sudo apt-get -y upgrade
sudo tasksel install openssh-server
sudo tasksel install mail-server
sudo tasksel install postgresql-server

2. Configure the mail server:


In our example setup, we’re going to configure as a ‘Satellite system’, forwarding all mail to our egress servers for delivery. You’ll probably want to do that unless you’re handling mail on the same machine as the Discourse software.


You probably want to configure your ‘mail name’ to be the base name of your domain. Note that this does not affect any email sent out by Discourse itself, just unqualified mail generated by systems programs.


If you have a mail server responsible for handling the egress of email from your network, enter it here. Otherwise, leave it blank.

3. Additional system packages

Install necessary packages:

# Run these commands as your normal login (e.g. "michael")
sudo apt-get -y install build-essential libssl-dev libyaml-dev git libtool libxslt-dev libxml2-dev libpq-dev gawk curl pngcrush imagemagick python-software-properties

# If you're on Ubuntu >= 12.10, change:
# python-software-properties to software-properties-common

4. Caching: Redis

Redis is a networked, in memory key-value store cache. Without the Redis caching layer, we’d have to go to the database a lot more often for common information and the site would be slower as a result.

Be sure to install the latest stable Redis, as the package in the distro may be a bit old:

sudo apt-add-repository -y ppa:rwky/redis
sudo apt-get update
sudo apt-get install redis-server

5. Web server - nginx

nginx is used for:

  • reverse proxy (i.e. load balancer)
  • static asset serving (since you don’t want to do that from ruby)
  • anonymous user cache

At Discourse, we recommend the latest version of nginx (we like the new and shiny). To install on Ubuntu:

# Run these commands as your normal login (e.g. "michael")
# Remove any existing versions of nginx
sudo apt-get remove '^nginx.*$'

# Add nginx repo to sources.list
cat <<'EOF' | sudo tee -a /etc/apt/sources.list

deb precise nginx
deb-src precise nginx

# Add nginx key
curl | sudo apt-key add -

# install nginx
sudo apt-get update && sudo apt-get -y install nginx

6. Install Ruby with RVM

We recommend installing RVM isolated to a single user’s environment.

7. Discourse setup

Create Discourse user:

Run these commands as your normal login (e.g. "michael")
sudo adduser --shell /bin/bash --gecos 'Discourse application' discourse
sudo install -d -m 755 -o discourse -g discourse /var/www/discourse

Give Postgres database rights to the discourse user:

# Run these commands as your normal login (e.g. "michael")
sudo -u postgres createuser -s discourse
# If you will be using password authentication on your database, only
# necessary if the database will be on a remote host
sudo -u postgres psql -c "alter user discourse password 'todayisagooddaytovi';"

Change to the ‘discourse’ user:

# Run this command as your normal login (e.g. "michael"), further commands should be run as 'discourse'
sudo su - discourse

Install RVM:

# As 'discourse'
# Install RVM
\curl -s -S -L | bash -s stable
. ~/.bash_profile

# rvm added shell initialization code to ~/.bash_profile,
# move it to ~/.profile instead
cat ~/.bash_profile >> ~/.profile
rm ~/.bash_profile

# Install necessary packages for building ruby (this will only work if
# you've given discourse sudo permissions, which is *not* the default)
# rvm requirements

# NOTE: rvm will tell you which packages you (or your sysadmin) need
# to install during this step. As discourse does not have sudo 
# permissions (likely the case), run:
rvm --autolibs=read-fail requirements
# repeat untill it fully executes 

Continue with Discourse installation:

# Build and install ruby
rvm install 2.0.0

# Use installed ruby as default
rvm use 2.0.0 --default

# Install bundler
gem install bundler

# Pull down the latest code
git clone git:// /var/www/discourse
cd /var/www/discourse
git checkout master

# To run on the most recent numbered release instead of bleeding-edge:
#git checkout latest-release

# Install necessary gems
bundle install --deployment --without test

If you have errors building the native extensions, ensure you have sufficient free system memory. 1GB with no swap isn’t enough, we recommend having 2GB as a minimum.

Configure Discourse:

# Run these commands as the discourse user
cd /var/www/discourse/config
cp database.yml.production-sample database.yml
cp redis.yml.sample redis.yml
cp discourse.pill.sample discourse.pill
cp environments/production.rb.sample environments/production.rb

Edit /var/www/discourse/config/database.yml

  • change production database name if appropriate
  • change database username/password if appropriate
  • if you are hosting multiple Discourse forums on the same server (multisite), set db_id
  • change host_names to the name you’ll use to access the discourse site, e.g. “”

Edit /var/www/discourse/config/redis.yml

  • no changes if this is the only application using redis, but have a look

Edit /var/www/discourse/config/discourse.pill

  • change application name from ‘discourse’ if necessary
  • Ensure appropriate Bluepill.application line is uncommented

Edit /var/www/discourse/config/environments/production.rb

  • browse througn all the settings
  • be sure to add your mail server SMTP settings so outgoing mail can be sent (we recommend Mandrill)
  • If your users will come from “internal” private unroutable IPs like 10.x.x.x or 192.168.x.x please see this topic.

Initialize the database:

# Run these commands as the discourse user
# The database name here should match the production one in database.yml
cd /var/www/discourse
createdb discourse_prod
RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production bundle exec rake db:migrate
RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production bundle exec rake assets:precompile

Not english? Set the default language as appropriate:

# Run these commands as the discourse user
cd /var/www/discourse
RAILS_ENV=production bundle exec rails c
SiteSetting.default_locale = 'fr'

# Not sure if your locale is supported? Check at the rails console:
 => ["cs", "da", "de", "en", "es", "fr", "id", "it", "nb_NO", "nl", "pseudo", "pt", "ru", "sv", "zh_CN", "zh_TW"]

8. Nginx setup

# Run these commands as your normal login (e.g. "michael")
sudo cp /var/www/discourse/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf

Edit /etc/nginx/nginx.conf:

  • add: server_names_hash_bucket_size 64; to the http section

If discourse will be the only site served by nginx, disable the nginx default site:

  • sudo mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.disabled
  • Otherwise, only server_names configured below in discourse.conf will be passed to Discourse.

Edit /etc/nginx/conf.d/discourse.conf

  • edit server_name. Example: server_name;
  • change socket count depending on your NUM_WEB count
  • change socket paths if discourse is installed to a different location
  • modify root location if discourse is installed to a different location

Reload nginx by running

# Run as your normal login (e.g. "michael")
sudo /etc/init.d/nginx reload

9. Bluepill setup

Configure Bluepill:

# Run these commands as the discourse user
gem install bluepill
echo 'alias bluepill="NOEXEC_DISABLE=1 bluepill --no-privileged -c ~/.bluepill"' >> ~/.bash_aliases
rvm wrapper $(rvm current) bootup bluepill
rvm wrapper $(rvm current) bootup bundle

Start Discourse:

# Run these commands as the discourse user
RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ROOT=/var/www/discourse RAILS_ENV=production NUM_WEBS=2 bluepill --no-privileged -c ~/.bluepill load /var/www/discourse/config/discourse.pill

Add the Bluepill startup to crontab.

# Run these commands as the discourse user
crontab -e

Add the following lines:

@reboot RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ROOT=/var/www/discourse RAILS_ENV=production NUM_WEBS=2 /home/discourse/.rvm/bin/bootup_bluepill --no-privileged -c ~/.bluepill load /var/www/discourse/config/discourse.pill

10. Log rotation setup

# Disabled for now - log rotation isn't *quite* complete
#0 0 * * * /usr/sbin/logrotate /var/www/discourse/config/logrotate.conf

11. Email setup

IMPORTANT: Discourse relies heavily on email. If your email configuration is not correct, you will effectively have a broken forum. Please, head over to our Mail Setup Guide to find out more information on how to properly setup emails.

Congratulations! You’ve got Discourse installed and running!