Debian 7 - Install Discourse

Discourse is a new style of forum that the makers of the StakcExchange network have been working on. Sites like Tek Syndicate and How-to-Geek are already using it, probably because it is fairly easy to deploy, and it appears to have a much more aesthetically pleasing look.

Note: We recommend deploying discourse on a server/VPS with at least 1 GB of RAM.

Steps

Install docker on the debian server.

Fetch Discourse

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

Configure The Discourse App

cd discourse_docker
cp samples/standalone.yml containers/app.yml

Run the following set of commands to prevent exposing SSH access to the rest of the world.

SEARCH='  - "2222:22"'
REPLACE='  - "127.0.0.1:2222:22"'
FILEPATH="containers/app.yml"
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH

We also need to set the hostname so that emails to users will link to the correct address. This is most noticeable with the account activation emails which will not work if you do not do this!

MY_IP_OR_HOSTNAME=[put your server's IP or full domain name here]
SEARCH="DISCOURSE_HOSTNAME: 'discourse.example.com'"
REPLACE="DISCOURSE_HOSTNAME: '$MY_IP_OR_HOSTNAME'"
FILEPATH="containers/app.yml"
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH

We need to configure ourselves to be admin with the following commands:

MY_EMAIL='[put your real email address here]'
SEARCH="DISCOURSE_DEVELOPER_EMAILS: 'me@example.com'"
REPLACE="DISCOURSE_DEVELOPER_EMAILS: '$MY_EMAIL'"
FILEPATH="containers/app.yml"
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH

Configure SMTP

If you're a Gmail user, you can create an app specific password and use that with the following set of commands to configure discourse for SMTP. If you're not a Gmail user, you can still run the commands below, but you need to lookup your SMTP details from your email provider, and you may need to change the port from 587.

PASSWORD="my gmail app specific password"
MY_EMAIL="my_username@gmail.com"

FILEPATH="containers/app.yml"

SEARCH='DISCOURSE_SMTP_ADDRESS: smtp.example.com'
REPLACE='DISCOURSE_SMTP_ADDRESS: smtp.gmail.com'
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH

SEARCH='#DISCOURSE_SMTP_USER_NAME: user@example.com      # (optional)'
REPLACE="DISCOURSE_SMTP_USER_NAME: $MY_EMAIL      # (optional)"
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH

SEARCH='#DISCOURSE_SMTP_PASSWORD: pa$$word               # (optional)'
REPLACE="DISCOURSE_SMTP_PASSWORD: $PASSWORD               # (optional)"
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH

Build the application

Every time you reconfigure Discourse, you need to rebuild the application, which will take a long time when executed for the first time. Make sure to wait for it to complete before moving onto the next section.

./launcher rebuild app

Login

Navigate to your server's hostname or IP in your browser.

Click "Sign up", and register the email you configured as an admin before. Then check your email and click on the link. You should now be setup! You can manage your site from YOUR_HOSTNAME_OR_IP/admin.

Migrating Server

All the "state" (such as the database data and uploaded content) is kept in /var/discourse/shared/standalone. Thus, to migrate to another server, perform the following steps:

  • Install discourse on the new server using the steps above.
  • Stop and remove the containers on both the old and new server.
  • Replace the /var/discourse/shared/standalone area on the new server with the files from the original using scp.
  • Run ./launcher rebuild app to rebuild the app on the new server and wait for the rebuild to finish.

References

Author

Programster

Stuart is a software developer with a passion for Linux and open source projects.

comments powered by Disqus
We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites. More info.