Beginners Guide to Install Discourse on Ubuntu for Development


(Arpit Jalan) #1

So you want to set up Discourse on Ubuntu to hack on and develop with?

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. Discourse uses Postgres 9.5, and Ubuntu 17.10 installs Postgrs 9.6, which has a different binary format, so it is recommended that you use an earlier version.

(If you want to install Discourse for production use, see our install guide)

Install Discourse Dependencies

As regular user run this script in terminal, to setup Rails development environment:

bash <(wget -qO- https://raw.githubusercontent.com/techAPJ/install-rails/master/linux)

This will install following new packages on your system:

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 (or your fork) in ~/discourse folder:

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

Setup Database

Open psql prompt as postgres user

sudo -u postgres psql postgres

Create role with the same name as your ubuntu system username with discourse as password:

CREATE ROLE techapj WITH LOGIN ENCRYPTED PASSWORD 'discourse' CREATEDB SUPERUSER;

In the above command, I named the role as techapj, this means that my ubuntu system username is techapj. (It is necessary for role name to be same as system username, otherwise migrations will not run)

Check that you have successfully created role:

\du

Create discourse_development and discourse_test database:

CREATE DATABASE discourse_development WITH OWNER techapj ENCODING 'UTF8' TEMPLATE template0;
CREATE DATABASE discourse_test WITH OWNER techapj ENCODING 'UTF8' TEMPLATE template0;

Exit psql prompt by pressing ctrld

Now access psql prompt in discourse_development database as techapj (your username) user:

psql -d discourse_development -U techapj -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 techapj (your username) user:

psql -d discourse_test -U techapj -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

source ~/.bashrc
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: (to have it available only on localhost)

bundle exec rails server

or use this command to have it listening on all interfaces and available remotely

bundle exec rails server --binding=0.0.0.0

You should now be able to connect to discourse app on http://localhost:3000 - try it out!

Create New Admin

To create a new admin, run the following commands:

RAILS_ENV=development
bundle exec rake admin:create

Just enter your input as suggested, you can create an admin account.

Configure Mail

Run MailCatcher:

mailcatcher --http-ip 0.0.0.0

Congratulations! You are now the admin of your own Discourse installation!

Happy hacking! And to get started with that, see Beginner’s Guide to Creating Discourse Plugins.


How can I make my own Discourse plugins?
How to add a new language
(Anton) #39

What should I do to upgrade discourse after git pull?
If anything is needed, then @techAPJ could you please add that to the guide?


(cpradio) #40

I do the following, no idea if it is correct though. :confused:

cd ~/discourse
git pull
bundle install
bundle exec rake db:migrate db:test:prepare 

Not Using A Supported Storage Driver
[SOLVED] Error while updating dev instance to latest version
(Arpit Jalan) #68

17 posts were split to a new topic: Getting errors when setting up Discourse dev environment on Ubuntu


Getting errors when setting up Discourse dev environment on Ubuntu
#86

Is it reasonable to use this installation for production as well?


(cpradio) #87

No. You will want to use the Docker install, that is the only installation supported in Production.


#91

Hello, I used this installation and everything works fine.
but-
I’m trying to connect remotely to postgres database using phppgadmin, but fails with ‘login failed’ error.
I tried to alter passwords for postgres and for discourse using:

./launcher enter app
su - postgres
psql
ALTER ROLE postgres WITH PASSWORD 'postgres';
ALTER ROLE discourse WITH PASSWORD 'discourse';

but still I cannot login through phppgadmin.
any idea?


(Sam Saffron) #92

You need to expose the pg port from inside the container to the machine/container running phpgadmin. Why not simply use data explorer?


#93

I’m referring to the development installation described in this discussion
and not the docker installation, this works just fine (I didn’t use the
launcher enter command as I wrote before… My mistake).

Can I view the db schema using Explorer?
If not, what do I have to do for the development installation db access
using phppgadmin to work?


(Kane York) #94

Yeah, the schema is shown on the right side of the editing box.


#95

I tried data explorer which is cool but I find phppgadmin more convenient in cases when lots of db work is needed.
Can anyone please tell how can I enable it on a development machine? I managed to do it only in docker. In dev, it seems no db service is listening on any port.


(cpradio) #96

You may want to read this topic


#97

thanks but no, it is again referring to the docker. I already managed to do it with the docker. I’m looking for a solution for the dev installation from this topic.


(cpradio) #98

Read the whole thing. PJH makes a backup and restores the backup locally.

I imagine you’ll have to do the same thing.


(Shriyansh Agrawal) #119

Hello folks,

I’m trying to setup Discourse on my local machine .
But everytime I run command ==> "bundle exec rake db:migrate db:test:prepare db:seed_fu"
It throw me out this error ==>

rake aborted!
TypeError: no implicit conversion of nil into String
/home/shriyansh/Academics/GSOC/discourse/lib/discourse_redis.rb:159:in block (3 levels) in <class:DiscourseRedis>'
/home/shriyansh/Academics/GSOC/discourse/lib/discourse_redis.rb:125:inignore_readonly'
/home/shriyansh/Academics/GSOC/discourse/lib/discourse_redis.rb:159:in block (2 levels) in <class:DiscourseRedis>'
/home/shriyansh/Academics/GSOC/discourse/config/initializers/100-secret_token.rb:6:in'
/home/shriyansh/Academics/GSOC/discourse/config/environment.rb:5:in `'
Tasks: TOP => db:migrate => environment

Can someone please help me out .


(Sam Saffron) #120

Not sure how you got into this state, if this was me I would be using puts in the various points in the stack to see what is going on.

See: I am a puts debuggerer | Tenderlovemaking


(Shriyansh Agrawal) #121

Hello @sam,

Here is my complete throwback error.Please look though it.
http://pastebin.com/zpS3vRQ9


(Sara Rey Chipps) #131

I am having the same issue, however, redis is up and running (ping/pong test works). Here is my trace, can someone help? I’m new to Ruby/Rails.

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
URGENT: no implicit conversion of nil into String Failed to initialize site default
rake aborted!
TypeError: no implicit conversion of nil into String
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/redis-3.2.2/lib/redis/connection/hiredis.rb:17:in `connect'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/redis-3.2.2/lib/redis/connection/hiredis.rb:17:in `connect'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:323:in `establish_connection'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:94:in `block in connect'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:280:in `with_reconnect'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:93:in `connect'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:351:in `ensure_connected'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:208:in `block in process'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:293:in `logging'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:207:in `process'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:113:in `call'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/redis-3.2.2/lib/redis.rb:822:in `block in get'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/redis-3.2.2/lib/redis.rb:57:in `block in synchronize'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/redis-3.2.2/lib/redis.rb:57:in `synchronize'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/redis-3.2.2/lib/redis.rb:821:in `get'
/home/vagrant/discourse/discourse/lib/discourse_redis.rb:159:in `block (3 levels) in <class:DiscourseRedis>'
/home/vagrant/discourse/discourse/lib/discourse_redis.rb:125:in `ignore_readonly'
/home/vagrant/discourse/discourse/lib/discourse_redis.rb:159:in `block (2 levels) in <class:DiscourseRedis>'
/home/vagrant/discourse/discourse/config/initializers/100-secret_token.rb:6:in `<top (required)>'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:268:in `load'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:268:in `block in load'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:268:in `load'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/engine.rb:652:in `block in load_config_initializer'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/notifications.rb:166:in `instrument'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/engine.rb:651:in `load_config_initializer'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/engine.rb:615:in `each'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/engine.rb:615:in `block in <class:Engine>'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/initializable.rb:30:in `instance_exec'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/initializable.rb:30:in `run'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:420:in `block (2 levels) in each_strongly_connected_component_from'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:419:in `block in each_strongly_connected_component_from'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/initializable.rb:44:in `each'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/initializable.rb:44:in `tsort_each_child'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:413:in `call'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:413:in `each_strongly_connected_component_from'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `each'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `call'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/initializable.rb:54:in `run_initializers'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/application.rb:352:in `initialize!'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/railtie.rb:194:in `public_send'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/railtie.rb:194:in `method_missing'
/home/vagrant/discourse/discourse/config/environment.rb:5:in `<top (required)>'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:274:in `require'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:274:in `block in require'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:274:in `require'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/application.rb:328:in `require_environment!'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/application.rb:457:in `block in run_tasks_blocks'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/task.rb:240:in `call'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/task.rb:201:in `block in invoke_prerequisites'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `each'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `invoke_prerequisites'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/task.rb:165:in `invoke'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/application.rb:150:in `invoke_task'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `each'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block in top_level'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/application.rb:115:in `run_with_threads'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/application.rb:100:in `top_level'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/application.rb:78:in `block in run'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/lib/rake/application.rb:75:in `run'
/home/vagrant/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rake-10.5.0/bin/rake:33:in `<top (required)>'
/home/vagrant/.rbenv/versions/2.2.3/bin/rake:22:in `load'
/home/vagrant/.rbenv/versions/2.2.3/bin/rake:22:in `<main>'
Tasks: TOP => db:migrate => environment

(Shriyansh Agrawal) #132

This happens with me too.
Try running commands the script from first step , again and check whether every command provided in that script goes well , and doesn’t throw any anonymous error.


(Sara Rey Chipps) #133

I just removed the whole folder and started over to the same result.

My local user name is vagrant and I replaced all the discourse user mentions with the vagrant user.

Any other tips?