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.
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.
There are a handful of prerequisites for running Discourse; this tutorial will assume a fresh Centos 6 VPS.
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.
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.
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.
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'
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
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
Ngnix is a lightweight web server and reverse proxy that will be used to reverse proxy connections to Discourse.
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:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1
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
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.
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:
exclude=postgresql*
under the [base]
and [updates]
sections of this file.
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
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
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
Ruby and rvm will be installed in single-user context for the discourse user.
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.
exit
sudo su - discourse
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.
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
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
Now the system is ready to build and run 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
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.
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.
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
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
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.
Now configure ngnix to point to the Discourse instance.
Log back in and execute these commands as the local user, not as discourse
.
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;
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;
}
/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.
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.
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.
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.activate
me.admin = true
me.save
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.
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.
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
https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md
I found I needed a different repo list from here: http://yum.postgresql.org/repopackages.php
1-5 instead of 1-4 http://yum.postgresql.org/9.1/redhat/rhel-6-x86_64/pgdg-redhat91-9.1-5.noarch.rpm
@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:
https://github.com/discourse/discourse/blob/master/docs/INSTALL-digital-ocean.md
Hi, I successfully followed your tutorial installing discourse 0.9.9.3 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?