How To Install Discourse on a CentOS 6.4 x64 VPS

Published on September 11, 2013

Jim Reardon

How To Install Discourse on a CentOS 6.4 x64 VPS

Status: Deprecated

This article covers a version of CentOS that is no longer supported. If you are currently operating a server running CentOS 6, we highly recommend upgrading or migrating to a supported version of CentOS.

Reason: CentOS 6 reached end of life (EOL) on November 30th, 2020 and no longer receives security patches or updates. For this reason, this guide is no longer maintained.

See Instead: This guide might still be useful as a reference, but may not work on other CentOS releases. If available, we strongly recommend using a guide written for the version of CentOS you are using.

About Discourse

Discourse is a new, open-source discussion platform. Designed as a complete ‘reboot’ of discussion forums, it has a different flow from conventional forums and a built in trust system.

Step 1: OS Configuration

There are a handful of prerequisites for running Discourse; this tutorial will assume a fresh Centos 6 VPS.

Add Swap Space

If you’re running a VPS with less than 2 GB of RAM, you’ll need to enable swap on your VPS. If you do not do so, some build steps are likely to fail.

This tutorial has instructions on enabling swap for CentOS 6. For smaller VPS, add at least 1 GB of swap space.

Create a local, non-root user

Most steps will be run as a non-root user with sudo access. This tutorial will run you through creating a user account and granting it sudo power.

Create a non-root user that will run Discourse

You’ll also need a user account which will run Discourse. It’s best for this to be a different account from your own; discourse would be a good choice.

Add the EPEL repository

EPEL stands for Extra Packages for Enterprise Linux, and it has some packages we’ll need to install that are not part of the base CentOS repositories.

Log in as your local user and run:

sudo su -c 'rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm'

Install required packages

These are pre-requisites for Discourse or its pre-requisites.

sudo yum install gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison iconv-devel ruby-devel libxml2 libxml2-devel libxslt libxslt-devel git

Install and start Redis

Redis is an open-source key value data store used by Discourse.

sudo yum install redis.x86_64
sudo chkconfig --add redis
sudo chkconfig --level 345 redis on
sudo /etc/init.d/redis start

Step 2: Install ngnix

Ngnix is a lightweight web server and reverse proxy that will be used to reverse proxy connections to Discourse.

Add repository

ngnix is not in the central CentOS repositories, so you will have to add their repository for yum to be able to install ngnix.

Create a text file /etc/yum.repos.d/nginx.repo:

sudo emacs /etc/yum.repos.d/nginx.repo

Paste in this content:

name=nginx repo

Once that’s installed, you need to refresh the yum package list and then install ngnix.

sudo yum upgrade
sudo yum install nginx.x86_64

Step 3: Install PostgreSQL

Discourse uses PostgreSQL for its data backend. While the EPEL contains packages for PostgreSQL, it’s fairly outdated. This will install a newer package from PostgreSQL’s repository.

Disable CentOS repository

First we’ll tell yum to not look at packages from the core CentOS repository. To do this, edit the file /etc/yum.repos.d/CentOS-Base.repo.

sudo emacs /etc/yum.repos.d/CentOS-Base.repo

Add the line:


under the [base] and [updates] sections of this file.

Install the PostgreSQL repository

Now we’ll register PostgreSQL’s repository with yum.

curl -O http://yum.postgresql.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpm
sudo rpm -ivh pgdg-centos91-9.1-4.noarch.rpm 

Install the PostgreSQL server

This will install the server and some development packages needed by Discourse, start the server, initialize the database, and set it to start on reboot.

sudo yum install postgresql91-server.x86_64 postgresql91-contrib.x86_64 postgresql91-devel.x86_64

sudo service postgresql-9.1 initdb
sudo service postgresql-9.1 start
sudo chkconfig postgresql-9.1 on

Grant permissions to users

Now tell PostgreSQL about our users and give them permission to access the database.

sudo -u postgres createuser -s root
sudo -u postgres createuser -s discourse

Step 4: Install rvm and Ruby

Ruby and rvm will be installed in single-user context for the discourse user.

Install rvm

Become the discourse user and install the stable branch of rvm:

sudo su - discourse
\curl -s -S -L https://get.rvm.io | bash -s stable

rvm will add some environment setup to the login scripts for the discourse user; to make sure these are set it’s easiest to log out then back in.

sudo su - discourse

Verify packages rvm requires are installed

This will make sure the environment is set up correctly and rvm is ready to work. Again, as the discourse user, run:

rvm --autolibs=read-fail requirements

This should return that no additional packages are required by rvm.

Install ruby

As the discourse user, install a local ruby environment and bundler:

rvm install 2.0.0
rvm use 2.0.0 --default
gem install bundler

Tweak ruby configuration

By default, the gem builder will not be able to find the support libraries and binaries for the system’s PostgreSQL server. In order for this gem to build, this will tell bundle to pass commandline arguments when it builds the PostgresSQL library.

Still as the discourse user, run:

bundle config build.pg --with-pgsql-lib=/usr/pgsql-9.1/lib --with-pg-config=/usr/pgsql-9.1/bin/pg_config

Step 5: Install and Configure Discourse

Now the system is ready to build and run Discourse.

Build Discourse

As the discourse user, pull down the Discourse source using git. This will clone the Discourse git tree to a sub-folder discourse:

git clone git://github.com/discourse/discourse.git discourse

Once that has copied the source locally, build Discourse:

cd discourse
bundle install --deployment --without test

Configure Discourse

Copy the example configuration files so Discourse will find them:

cd 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

You’ll need to edit database.yml. Change the host_names line to your server’s hostname.

Create database

Return to the discourse directory, and as the discourse user run:

cd ~/discourse
createdb discourse_prod
RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production rake db:migrate
RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production rake assets:precompile

The precompile step can take several minutes without printing any output to the screen, so it may appear like the process has hung.

Fix permissions

By default the webserver will not be able to access the discourse directory. To grant more broad permissions, run this as the discourse user:

cd ~
chmod og+rx /home/discourse

Install and configure bluepill

Bluepill is a process monitoring tool that Discourse uses to monitor itself. Install and configure it to start on boot:

gem install bluepill
echo 'alias bluepill="NOEXEC_DISABLE=1 bluepill --no-privileged -c ~/.bluepill"' >> ~/.bash_profile
rvm wrapper $(rvm current) bootup bluepill
rvm wrapper $(rvm current) bootup bundle

Run Discourse

Discourse is now ready to start up. To start Discourse, run:

RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ROOT=/home/discourse/discourse RAILS_ENV=production NUM_WEBS=2 bluepill --no-privileged -c ~/.bluepill load /home/discourse/discourse/config/discourse.pill

You should also configure Discourse to start at bootup by adding this to the discourse user’s crontab. Open up your crontab for editing:

crontab -e

And paste the following line into the editor that pops up:

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

Discourse is now running, but ngnix needs to be configured to forward requests to the running Discourse server before it will answer requests sent to your hostname.

Step 7: Configure ngnix

Now configure ngnix to point to the Discourse instance.

Log back in and execute these commands as the local user, not as discourse.

Base ngnix configuration

There’s a small change you’ll need to make to the configuration. Open the /etc/nginx/nginx.conf file:

sudo emacs /etc/nginx/nginx.conf

Find the http section of the file and add the following line:

server_names_hash_bucket_size 64;

Configure nginx for Discourse

Discourse comes with an example nginx configuration file. Copy the example Discourse ngnix configuration to where ngnix expects it:

sudo cp /home/discourse/discourse/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf

There are a few changes that need to be made to this file. Open the `/etc/nginx/conf.d/discourse.conf’ file:

sudo emacs /etc/nginx/conf.d/discourse.conf
  • Change server_name to your hostname.

  • Change the socket paths to reflect where Discourse is installed. They should look like this:

upstream discourse {
  server unix:/home/discourse/discourse/tmp/sockets/thin.0.sock;
  server unix:/home/discourse/discourse/tmp/sockets/thin.1.sock;
  server unix:/home/discourse/discourse/tmp/sockets/thin.2.sock;
  server unix:/home/discourse/discourse/tmp/sockets/thin.3.sock;
  • Change the base path in the file. Look for a line with a path /var/www/discourse/public and replace this with our correct path, /home/discourse/discourse/public.

Now restart ngnix to pick up the configuration changes:

sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx start

The stop command may fail if ngnix wasn’t currently running, but the start command should succeed.

Step 8: Use Discourse!

Discourse is now running and responding to requests at your hostname. The last thing you’ll need to do is set up an admin account to give you permission to administrate the Discourse instance.

Create your Discourse user

Open your Discourse website by navigating to your hostname in your webbrowser. Create a user account for yourself and make note of the email address with which you sign up.

Grant yourself administrative priveleges

Return back to your shell. Become the discourse user and bring up a rails console connected to the Discourse instance:

cd ~/discourse
RAILS_ENV=production bundle exec rails c

This will drop you into a Rails console where you can run commands. These commands will grant you administrative access; replace the email address with the email address you signed up with:

me = User.find_by_username_or_email('myemailaddress@me.com')
me.admin = true

You can also set this user as the default contact, as well:

SiteSetting.site_contact_username = me.username

Type exit to quit the Rails console.

Verify you are now an administrator

Return back to your Discourse instance in your webbrowser. If you’re not logged in as the account you signed up for, log back in. You will now be able to configure your Discourse instance to your liking.

Congratulations! You’ve installed Discourse. Huzzah!

<div class=“author”>Submitted by: <a href=“http://jimreardon.us/”>Jim Reardon</a></div>

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

Learn more about our products

About the authors
Default avatar
Jim Reardon


Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?

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!

DO NOT USE THIS! It is completely out of date. See the current installation instructions at


Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
May 7, 2014

@jonny.mccullagh: Unfortunately, the process to update to a new release isn’t particularly straight forward. More or less, inside the git repository you run a “git pull” and then go through the steps again just using your existing configuration files and database. The Discourse team has recently been promoting the idea of running it inside of a Docker container and have even build an auto-update plugin for those using it that way. There is a tutorial here:


Hi, I successfully followed your tutorial installing discourse on centos 6. I am interested in knowing how I would perform upgrades when new versions of discourse are released? Thanks, jonny

Answering my own question: According to this guide you need at least 1GB of RAM: https://github.com/baus/install-discourse

Could you say anything about what kind of Droplet/specs are required to run Discourse? I’ve heard that it’s very heavy on resources, depending on traffic of course…

Is there any guide for LAMP OR on apache installation

to fix, do the following:

bundle install --no-deployment gem install ember-source -v=1.0.0.rc6.2 bundle

then try again. if you get an error about hstore with postgresql, do this: sudo yum install postgresql92-contrib.x86_64

then log into your postgresql db and… CREATE EXTENSION hstore; \q

then run the rake command again. should be dandy.

Running on the same problems.

gem install rake didn’t work, however, when I added -v=10.0.4 it did work. Then I get an error about not finding another gem.

So its almost like my bundle install didn’t install all the relevant gems. Yet, when I check the bundle directory all the gems are there. Is there a way to point ruby to the correct gem directory?

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!

Featured on Community

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