How To Install and Setup Discourse on an Ubuntu 12.04 VPS


discourse

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 [email protected]

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

[email protected]:~$ \curl -s -S -L https://get.rvm.io | bash
[email protected]:~$ source ~/.rvm/scripts/rvm
[email protected]:~$ rvm install ruby

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

[email protected]:~$ ruby --version
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]

Install bundler

[email protected]:~$ gem install bundler

Setup Bluepill

gem install bluepill
[email protected]:~$ echo 'alias bluepill="NOEXEC_DISABLE=1 bluepill --no-privileged -c ~/.bluepill"' >> ~/.bashrc
[email protected]:~$ source ~/.bashrc
[email protected]:~$ rvm wrapper $(rvm current) bootup bluepill
[email protected]:~$ 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

[email protected]:~$ cd /var/www/discourse
[email protected]:~$ git clone git://github.com/discourse/discourse.git . # do not forget the dot at the end
[email protected]:~$ bundle install --deployment --without test

Set up Discourse

Copy the example configuration files

[email protected]:~$ cp config/discourse_quickstart.conf config/discourse.conf
[email protected]:~$ cp config/discourse.pill.sample config/discourse.pill

Edit the discourse.conf file

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

Initialize Discourse database

cd /var/www/discourse
[email protected]:~$ createdb discourse_prod
[email protected]:~$ RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production bundle exec rake db:migrate
[email protected]:~$ 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

[email protected]:~$ sudo cp /var/www/discourse/config/nginx.global.conf /etc/nginx/conf.d/local-server.conf
[email protected]:~$ sudo cp /var/www/discourse/config/nginx.sample.conf /etc/nginx/sites-available/discourse.conf
[email protected]:~$ sudo ln -s /etc/nginx/sites-available/discourse.conf /etc/nginx/sites-enabled/discourse.conf
[email protected]:~$ sudo vim /etc/nginx/sites-enabled/discourse.conf # change the server_name (ex: yourSub.domain.org)
[email protected]:~$ sudo /etc/init.d/nginx restart

Create an admin account

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

Back to the shell prompt

cd /var/www/discourse
[email protected]:~$ RAILS_ENV=production bundle exec rails c
2.1.0 :001 > me = User.find_by_username_or_email('[email protected]')
2.1.0 :002 > me.activate
2.1.0 :003 > me.admin = true
2.1.0 :004 > me.save
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.

Tutorials
Install Moodle on a Linux VPS
Tutorials
How Can I Move My Blog from WordPress.com to My Own Domain?
Tutorials
How to Install Odoo 10 on an Ubuntu 16.04 VPS
There are currently no comments.

 
Free Migration to RoseHosting. Award Winning Linux VPS Hosting with Fully Managed Support. Coupon RHBLOG50 for 50% offOrder Now
+