So you want to set up Discourse on Ubuntu to hack on and develop with?
If so, the easiest thing to do is use Vagrant. It is dramatically easier. If you like doing things the hard way, read on!
We’ll assume that you don’t have Ruby/Rails/Postgre/Redis installed on your Ubuntu system. Let’s begin!
Although this guide assumes that you are using Ubuntu, but the set-up instructions will work fine for any Debian based distribution.
(If you want to install Discourse for production use, see our install guide)
Install Discourse Dependencies
Run this script in terminal, to setup Rails development environment:
bash
This will install following new packages on your system:
- Git
- rbenv
- ruby-build
- Ruby (stable)
- Rails
- PostgreSQL
- SQLite
- Redis
- Bundler
- ImageMagick
Install Phantomjs:
For 32 bit macine:
cd /usr/local/share
sudo wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-i686.tar.bz2
sudo tar xvf phantomjs-1.9.8-linux-i686.tar.bz2
sudo rm phantomjs-1.9.8-linux-i686.tar.bz2
sudo ln -s /usr/local/share/phantomjs-1.9.8-linux-i686/bin/phantomjs /usr/local/bin/phantomjs
cd
For 64 bit machine:
cd /usr/local/share
sudo wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
sudo tar xvf phantomjs-1.9.8-linux-x86_64.tar.bz2
sudo rm phantomjs-1.9.8-linux-x86_64.tar.bz2
sudo ln -s /usr/local/share/phantomjs-1.9.8-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs
cd
In case you have any of this package pre-installed and don’t want to run entire script, see the script and pick the packages you don’t have currently installed. The script is fine-tuned for Discourse, and includes all the packages required for Discourse installation.
Now that we have installed Discourse dependencies, let’s move on to install Discourse itself.
Clone Discourse
Clone the Discourse repository in ~/discourse
folder:
git clone https://github.com/discourse/discourse.git ~/discourse
Setup Database
Open psql prompt as postgre user
sudo -u postgres psql postgres
Create role with the same name as your ubuntu system username with discourse as password:
CREATE ROLE discourse WITH LOGIN ENCRYPTED PASSWORD 'discourse' CREATEDB SUPERUSER;
In the above command, I named the role as discourse, this means that my ubuntu system username is discourse. (It is necessary for role name to be same as system username, otherwise migrations will not run)
Check that you have successfully created discourse role:
\du
Create discourse_development and discourse_test database:
CREATE DATABASE discourse_development WITH OWNER discourse ENCODING 'UTF8' TEMPLATE template0;
CREATE DATABASE discourse_test WITH OWNER discourse ENCODING 'UTF8' TEMPLATE template0;
Exit psql prompt by pressing ctrld
Now access psql prompt in discourse_development database as discourse user:
psql -d discourse_development -U discourse -h localhost
When prompted for password, provide the password which you set at the time of creating role, if you followed the guide as is, the password is discourse
Run following commands, separately:
CREATE EXTENSION pg_trgm;
CREATE EXTENSION hstore;
Exit psql prompt by pressing ctrld
Now access psql prompt in discourse_test database as discourse user:
psql -d discourse_test -U discourse -h localhost
When prompted for password, provide the password which you set at the time of creating role, if you followed the guide as is, the password is discourse
Run following commands, separately:
CREATE EXTENSION pg_trgm;
CREATE EXTENSION hstore;
Exit psql prompt by pressing ctrld
You have set-up the database successfully!
Bootstrap Discourse
Switch to your Discourse folder:
cd ~/discourse
Install the needed gems
bundle install
Now that you have successfully configured database connection, run this command:
bundle exec rake db:migrate db:test:prepare db:seed_fu
Now, try running the specs:
bundle exec rake autospec
Start rails server:
bundle exec rails server
You should now be able to connect to discourse app on http://localhost:3000 - try it out!
Configure Mail and Create New Account
We will use MailCatcher to serve emails in development environment. Install and run MailCatcher:
gem install mailcatcher
mailcatcher --http-ip 0.0.0.0
Create new account:
Check confirmation email by going to MailCatcher web interface at http://localhost:1080/
If you did not receive the email, try running this in console: bundle exec sidekiq -q default
Click the confirmation link and your account will be activated!
Access Admin
Now, to make your account as admin, run the following commands in rails console:
RAILS_ENV=development bundle exec rails c
u = User.last
u.admin = true
u.save
Once you execute the above commands successfully, check out your Discourse account again:
Congratulations! You are now the admin of your own Discourse installation!
Happy hacking!
If anything needs to be improved in this guide, feel free to ask on meta.discourse.org, or even better, submit a pull request.
Source: https://meta.discourse.org/t/beginners-guide-to-install-discourse-on-ubuntu-for-development/14727