Discourse is a 100% open source discussion platform built for the next decade of the Internet. Use it as a mailing list, discussion forum, long-form chat room, and more! This guide will detail how to deploy a development discourse server using a SkySilk VPS. 

*Note: Production Discourse Servers require Docker support for installation. Docker is not currently supported by SkySilk. This method is intended to instruct for development Discourse only. This guide assumes that you are using Debian 9.


How to Install Discourse (without Docker) using SkySilk VPS 


   1. Deploy a SkySilk VPS running Debian 9.

   2. Login to your VPS. SSH into your VPS using the SSH Console on your user dashboard, or by using another SSH terminal.

       If you are connecting from a Unix-like machine (Mac OS or Linux), or by using PuTTY with Windows then the command to connect is simply:

ssh [user]@[ip address]

where [user] is your username, typically root, and [ip address] is the IP address of the virtual machine, for example:

ssh root@204.44.81.XX

(Read: How To Access Linux VPS via SSH Key)


3. Update the System:

apt update
apt upgrade


4. Add the needed repositories.

echo deb http://packages.dotdeb.org stretch all > /etc/apt/sources.list.d/dotdeb.list
wget https://www.dotdeb.org/dotdeb.gpg -O - | apt-key add -

echo deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main > /etc/apt/sources.list.d/postgresql.list
wget -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -

apt update


5. Install Nginx, Postgresql, git and redis-server.

apt install nginx postgresql-9.5 git redis-server


6. Connect to Postgresql server and initialize the Discourse Database.

su - postgres -c psql

CREATE DATABASE discourse;
CREATE USER discourse;
ALTER USER discourse WITH ENCRYPTED PASSWORD 'password';
ALTER DATABASE discourse OWNER TO discourse;
\connect discourse
CREATE EXTENSION hstore;
CREATE EXTENSION pg_trgm;


Press ctrl+D to exit


7. Clone the Discourse repo into /root/discourse.

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


8. Manually configure PPA and Install RVM.

apt install dirmngr

echo deb http://ppa.launchpad.net/rael-gc/rvm/ubuntu bionic main > /etc/apt/sources.list.d/rael-gc-ubuntu-rvm-bionic.list
echo deb-src http://ppa.launchpad.net/rael-gc/rvm/ubuntu bionic main >> /etc/apt/sources.list.d/rael-gc-ubuntu-rvm-bionic.list
apt-key adv  --recv-keys 7BE3E5681146FD4F1A40EDA28094BB14F4E3FBBE

apt update
apt install rvm


9. Install ruby 2.4.

source /etc/profile.d/rvm.sh
rvm install 2.4


10. Set Ruby 2.4 as default version.

rvm use 2.4


11. Install package to acquire pq header files.

apt install libpq-dev


12. Install bundler.

gem install bundler


13. Install dependencies for Discourse.

cd /root/discourse
bundle install


14. Create configfile for Discourse

cp config/discourse_defaults.conf config/discourse.conf


Note: Make sure you edit discourse.conf to reflect the setup you need. Following the general rule of if you don't understand it don't change it before consulting Google or someone who knows what they're doing. This is also where you input SMTP settings. Without an SMTP server you will not be able to create an Admin account for Discourse.


15. After editing the config we begin preparing Discourse for deployment.

RAILS_ENV=production bundle exec rake db:migrate
RAILS_ENV=production bundle exec rake assets:precompile


16. Once that's complete edit config/puma.rb with the following content:

if ENV['RAILS_ENV'] == 'production'

  # First, you need to change these below to your situation.
  APP_ROOT = '/root/discourse'
  num_workers = 1

  # Second, you can choose how many threads that you are going to run at same time.
  workers "#{num_workers}"
  threads 1, 1

  # Unless you know what you are changing, do not change them.
  bind "unix://#{APP_ROOT}/tmp/sockets/puma.sock"
  stdout_redirect "#{APP_ROOT}/log/puma.log", "#{APP_ROOT}/log/puma.err.log"
  pidfile "#{APP_ROOT}/tmp/pids/puma.pid"
  state_path "#{APP_ROOT}/tmp/pids/puma.state"
  daemonize false
  preload_app!

end


If you followed the tutorial exactly the above config should work for you.


17. Now before running Discourse we need to fix a mistake with Puma.

mkdir /root/discourse/tmp/{sockets,pids}


18. Now it's time to setup Nginx to forward the requests to Discourse. Create /etc/nginx/conf.d/discourse.conf with the following content:

upstream discourse {
    server unix:/root/discourse/tmp/sockets/puma.sock;
}

server {
    listen 80;

    server_name your.domain.here;

    set $public /root/discourse/public;

    root $public;

    try_files $uri @proxy;

    location @proxy {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://discourse;
    }
}


Note: Replace ‘your.domain.here’ with your own registered domain!



19. Now edit /etc/nginx/nginx.conf and set user as ‘root’:


user root;


20. Now we need to setup the services for Discourse.

rvm wrapper 2.4 systemd bundle


21. Now create the file config/sidekiq.yml with the following:

---
:concurrency: 5
:pidfile: tmp/pids/sidekiq.pid
staging:
  :concurrency: 10
production:
  :concurrency: 20
:queues:
  - default
  - critical
  - low


22. Next create the file /etc/systemd/system/discourse-sidekiq.service with the content:

[Unit]
Description=discourse sidekiq service
After=multi-user.target

[Service]
WorkingDirectory=/root/discourse
Environment=RAILS_ENV=production
ExecStart=/usr/share/rvm/bin/systemd_bundle exec sidekiq -C config/sidekiq.yml
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target


23. The next file we need to create is /etc/systemd/system/discourse.service with the content:

[Unit]
Description=discourse service
After=discourse-sidekiq.service
Requires=discourse-sidekiq.service

[Service]
WorkingDirectory=/root/discourse
Environment=RAILS_ENV=production
ExecStart=/usr/share/rvm/bin/systemd_bundle exec puma -C config/puma.rb
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target


24. Restart services to apply configured changes.

service nginx stop
service nginx restart
service discourse stop
service discourse restart


25. Follow the instructions at this URL for upgrading and installing plugins: https://bcarlin.net/blog/discourse-without-docker.html


  You should now be able to connect to discourse app!


For additional resources on specifics of using Discourse, please consult Discourse Support and Community reference material:

Discourse.org

Support and Community


CLICK TO DEPLOY A HOSTED DISCOURSE SERVER