How To Install and Setup Discourse on an Ubuntu 12.04 VPS


Discourse is an open source, next-generation discussion software written in JavaScript and Ruby on Rails. Discourse is built by the team behind the Stack Exchange and Stack Overflow networks.
Today, we will walk you through the process of installing and setting up Discourse in Ubuntu 12.04 LTS.

Login to your server using SSH

ssh username@hostname

Update the system and install all the necessary packages.

~ # ❯❯❯ sudo apt-get -y update && apt-get -y upgrade
~ # ❯❯❯ 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 sed

Create a new Discourse user:

~ # ❯❯❯ sudo adduser --shell /bin/bash --gecos 'Discourse application' discourse
~ # ❯❯❯ sudo install -d -m 755 -o discourse -g discourse /var/www/discourse
~ # ❯❯❯ sudo usermod -a -G sudo discourse

Install the the latest version of PostgreSQL and create a discourse DB user

~ # ❯❯❯ sudo apt-get -y install postgresql postgresql-contrib
~ # ❯❯❯ sudo -u postgres createuser -s discourse
~ # ❯❯❯ sudo -u postgres psql -c "alter user discourse password 'DiscoursePazzW0rt';"

Install the the latest version of Redis

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

Install the latest version of Nginx

~ # ❯❯❯ sudo add-apt-repository -y ppa:nginx/stable
~ # ❯❯❯ sudo apt-get update
~ # ❯❯❯ sudo apt-get install -y nginx

Set the worker_processes to the number of processors in your system. To find out the number of processors in your system and set the worker_processes, run the following command:

~ # ❯❯❯ sudo sed -i "0,/^worker_processes/ s/^worker_processes .*$/worker_processes `grep -c processor /proc/cpuinfo`;/"  /etc/nginx/nginx.conf

Install a mail server

~ # ❯❯❯ sudo apt-get install -y postfix

For more detailed instruction on how to setup a mail server please click here

Switch to the discourse user

~ # ❯❯❯ sudo su - discourse

Install Ruby using RVM

discourse@rh:~$ \curl -s -S -L | bash
discourse@rh:~$ source ~/.rvm/scripts/rvm
discourse@rh:~$ rvm install ruby

To verify everything is done correctly, use the command “ruby -v”.
The output should be similar to the following:

discourse@rh:~$ ruby --version
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]

Install bundler

discourse@rh:~$ gem install bundler

Setup Bluepill

gem install bluepill
discourse@rh:~$ echo 'alias bluepill="NOEXEC_DISABLE=1 bluepill --no-privileged -c ~/.bluepill"' >> ~/.bashrc
discourse@rh:~$ source ~/.bashrc
discourse@rh:~$ rvm wrapper $(rvm current) bootup bluepill
discourse@rh:~$ rvm wrapper $(rvm current) bootup bundle

add the Bluepill to crontab

crontab -e
@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

Pull down the latest Discourse code

discourse@rh:~$ cd /var/www/discourse
discourse@rh:~$ git clone git:// . # do not forget the dot at the end
discourse@rh:~$ bundle install --deployment --without test

Set up Discourse

Copy the example configuration files

discourse@rh:~$ cp config/discourse_quickstart.conf config/discourse.conf
discourse@rh:~$ cp config/discourse.pill.sample config/discourse.pill

Edit the discourse.conf file

vim config/discourse.conf
  • Change the hostname (ex:
  • Set the password for discourse DB user – db_password (ex: DiscoursePazzW0rt)
  • Set the mail config options

Initialize Discourse database

cd /var/www/discourse
discourse@rh:~$ createdb discourse_prod
discourse@rh:~$ RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production bundle exec rake db:migrate
discourse@rh:~$ RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production bundle exec rake assets:precompile

Start Discourse

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

Configure Nginx

discourse@rh:~$ sudo cp /var/www/discourse/config/ /etc/nginx/conf.d/local-server.conf
discourse@rh:~$ sudo cp /var/www/discourse/config/nginx.sample.conf /etc/nginx/sites-available/discourse.conf
discourse@rh:~$ sudo ln -s /etc/nginx/sites-available/discourse.conf /etc/nginx/sites-enabled/discourse.conf
discourse@rh:~$ sudo vim /etc/nginx/sites-enabled/discourse.conf # change the server_name (ex:
discourse@rh:~$ sudo /etc/init.d/nginx restart

Create an admin account

Open your browser of choice, navigate to your domain (ex:, click on Login and create a new account.

Back to the shell prompt

cd /var/www/discourse
discourse@rh:~$ RAILS_ENV=production bundle exec rails c
2.1.0 :001 > me = User.find_by_username_or_email('')
2.1.0 :002 > me.activate
2.1.0 :003 > me.admin = true
2.1.0 :004 >
2.1.0 :004 > SiteSetting.site_contact_username = me.username

That’s it. The admin account is created, and you can now start using your new forum.

Of course you don’t have to do any of this if you use one of our Linux VPS hosting services, in which case you can simply ask our expert linux admins to install this on your server for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

How to Install LCMP (Cherokee, MySQL and PHP) on CentOS 6 / RHEL 6 / Scientific Linux 6
How to install Squirrelmail on CentOS 6
Install PHP 7 on CentOS 7
There are currently no comments.