Beginners Guide to Install Discourse on Ubuntu for Development

You could just use the docker dev setup, it works great and perf penalty is no high at all

3 Likes

Hello,
Thank your for this beginner’s guide. I have a question concerning the following line

RAILS_ENV=test bundle exec rake db:create db:migrate

When I run this line in my terminal. I get the following error:

PG::InsufficientPrivilege: ERROR: permission denied to create extension "hstore" HINT: Must be superuser to create this extension.

Do you have any ideas why that might be the case? I google it but I have only found a guide to create a superuser. Yet creating a superuser did not solve this problem.

Thanks for your answer.

3 Likes

Sound to me like the user you have is not properly a super user on the database.

Maybe do a sudo -u postgres psql discourse_development and then try creating the extension? I think you need trigram as well, so you might as well make your end user superuser on the local development machine.

5 Likes

That was exactly my problem. I stopped postgres.exe from windows and it worked ! thanks Sam

5 Likes

Hi, When I run bundle exec rake autospec, it reports error as follows:

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) PostAction#add_moderator_post_if_needed should not add a moderator post when post is flagged via private message
     # No reason given
     # ./spec/models/post_action_spec.rb:923

  2) Theme #transform_ids works with nil values
     # Temporarily skipped with xit
     # ./spec/models/theme_spec.rb:70


Failures:

  1) Migration::ColumnDropper.mark_readonly should prevent updates to the readonly column
     Failure/Error: expect(e.message).to include(message)

       expected "ERROR:  Discourse: email in table_with_readonly_column is readonly\n" to include "discourse_functions.raise_table_with_readonly_column_email_readonly()"
       Diff:
       @@ -1,2 +1,2 @@
       -discourse_functions.raise_table_with_readonly_column_email_readonly()
       +ERROR:  Discourse: email in table_with_readonly_column is readonly

     # ./spec/components/migration/column_dropper_spec.rb:87:in `block (4 levels) in <main>'
     # ./spec/components/migration/column_dropper_spec.rb:86:in `each'
     # ./spec/components/migration/column_dropper_spec.rb:86:in `rescue in block (3 levels) in <main>'
     # ./spec/components/migration/column_dropper_spec.rb:76:in `block (3 levels) in <main>'
     # ------------------
     # --- Caused by: ---
     # PG::RaiseException:
     #   ERROR:  Discourse: email in table_with_readonly_column is readonly
     #   ./spec/components/migration/column_dropper_spec.rb:77:in `block (3 levels) in <main>'

  2) ApplicationController#handle_theme does not allow non privileged user to preview themes
     Failure/Error: expect(controller.theme_ids).to eq([SiteSetting.default_theme_id])

       expected: [-1]
            got: []

       (compared using ==)
     # ./spec/requests/application_controller_spec.rb:329:in `block (3 levels) in <main>'

  3) ApplicationController#handle_theme selects the theme the user has selected
     Failure/Error: expect(controller.theme_ids).to eq([SiteSetting.default_theme_id])

       expected: [-1]
            got: []

       (compared using ==)
     # ./spec/requests/application_controller_spec.rb:283:in `block (3 levels) in <main>'

  4) Wizard::Builder colors step when the default theme has not been override should set the right default values
     Failure/Error: SiteSetting.find_by(name: "default_theme_id").destroy!

     NoMethodError:
       undefined method `destroy!' for nil:NilClass
     # ./spec/components/wizard/wizard_builder_spec.rb:156:in `block (4 levels)in <main>'

  5) Wizard::Builder colors step when the default them hass been override should set the right default values
     Failure/Error: expect(field.required).to eq(false)

       expected: false
            got: true

       (compared using ==)
     # ./spec/components/wizard/wizard_builder_spec.rb:171:in `block (4 levels)in <main>'

  6) Migration::TableDropper.readonly_only_table should prevent insertions to the table
     Failure/Error: expect(e.message).to include(message)

       expected "ERROR:  Discourse: table_with_old_name is read only\n" to include "discourse_functions.raise_table_with_old_name_readonly()"
       Diff:
       @@ -1,2 +1,2 @@
       -discourse_functions.raise_table_with_old_name_readonly()
       +ERROR:  Discourse: table_with_old_name is read only

     # ./spec/components/migration/table_dropper_spec.rb:69:in `block (4 levels) in <main>'
     # ./spec/components/migration/table_dropper_spec.rb:68:in `each'
     # ./spec/components/migration/table_dropper_spec.rb:68:in `rescue in block(3 levels) in <main>'
     # ./spec/components/migration/table_dropper_spec.rb:60:in `block (3 levels) in <main>'
     # ------------------
     # --- Caused by: ---
     # PG::RaiseException:
     #   ERROR:  Discourse: table_with_old_name is read only
     #   (eval):24:in `async_exec'

Finished in 13 minutes 21 seconds (files took 13.46 seconds to load)
11151 examples, 6 failures, 2 pending

Failed examples:

rspec ./spec/components/migration/column_dropper_spec.rb:75 # Migration::ColumnDropper.mark_readonly should prevent updates to the readonly column
rspec ./spec/requests/application_controller_spec.rb:326 # ApplicationController#handle_theme does not allow non privileged user to preview themes
rspec ./spec/requests/application_controller_spec.rb:272 # ApplicationController#handle_theme selects the theme the user has selected
rspec ./spec/components/wizard/wizard_builder_spec.rb:159 # Wizard::Builder colors step when the default theme has not been override should set the right default values
rspec ./spec/components/wizard/wizard_builder_spec.rb:170 # Wizard::Builder colors step when the default them hass been override should set the right default values
rspec ./spec/components/migration/table_dropper_spec.rb:59 # Migration::TableDropper.readonly_only_table should prevent insertions to the table

Randomized with seed 34183

How to solve this problem?

1 Like

14 posts were split to a new topic: Permission denied during Ubuntu developer setup

I’m getting a similar problem:

satisfied expectations:
- allowed any number of times, not yet invoked: DateTime.now(any_parameters)
....................................................................................................................................................................................................................................................................................................................................................................................................................................

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) PostAction#add_moderator_post_if_needed should not add a moderator post when post is flagged via private message
     # No reason given
     # ./spec/models/post_action_spec.rb:923

  2) Theme #transform_ids works with nil values
     # Temporarily skipped with xit
     # ./spec/models/theme_spec.rb:70


Failures:

  1) ApplicationController#handle_theme does not allow non privileged user to preview themes
     Failure/Error: expect(controller.theme_ids).to eq([SiteSetting.default_theme_id])
     
       expected: [-1]
            got: []
     
       (compared using ==)
     # ./spec/requests/application_controller_spec.rb:329:in `block (3 levels) in <main>'

  2) ApplicationController#handle_theme selects the theme the user has selected
     Failure/Error: expect(controller.theme_ids).to eq([SiteSetting.default_theme_id])
     
       expected: [-1]
            got: []
     
       (compared using ==)
     # ./spec/requests/application_controller_spec.rb:283:in `block (3 levels) in <main>'

  3) Wizard::Builder colors step when the default them hass been override should set the right default values
     Failure/Error: expect(field.required).to eq(false)
     
       expected: false
            got: true
     
       (compared using ==)
     # ./spec/components/wizard/wizard_builder_spec.rb:171:in `block (4 levels) in <main>'

  4) Wizard::Builder colors step when the default theme has not been override should set the right default values
     Failure/Error: SiteSetting.find_by(name: "default_theme_id").destroy!
     
     NoMethodError:
       undefined method `destroy!' for nil:NilClass
     # ./spec/components/wizard/wizard_builder_spec.rb:156:in `block (4 levels) in <main>'

Finished in 10 minutes 15 seconds (files took 8.67 seconds to load)
11190 examples, 4 failures, 2 pending

Failed examples:

rspec ./spec/requests/application_controller_spec.rb:326 # ApplicationController#handle_theme does not allow non privileged user to preview themes
rspec ./spec/requests/application_controller_spec.rb:272 # ApplicationController#handle_theme selects the theme the user has selected
rspec ./spec/components/wizard/wizard_builder_spec.rb:170 # Wizard::Builder colors step when the default them hass been override should set the right default values
rspec ./spec/components/wizard/wizard_builder_spec.rb:159 # Wizard::Builder colors step when the default theme has not been override should set the right default values

Randomized with seed 1957

If I press ENTER, it tries with a different seed and some of these disappears, until I have one that persists:

Failures:

  1) Wizard::Builder colors step when the default theme has not been override should set the right default values
     Failure/Error: SiteSetting.find_by(name: "default_theme_id").destroy!
     
     NoMethodError:
       undefined method `destroy!' for nil:NilClass
     # ./spec/components/wizard/wizard_builder_spec.rb:156:in `block (4 levels) in <top (required)>'

Finished in 0.23227 seconds (files took 2.01 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/components/wizard/wizard_builder_spec.rb:159 # Wizard::Builder colors step when the default theme has not been override should set the right default values

Randomized with seed 7847

Any ideas on how to solve this type of problem?

I find this command is optional, so I ignore run this command, it also works.:joy:

Yeah I saw that previously … and @codinghorror also saw it the other day.

Can you try:

redis-cli flushall
bin/rake db:drop
bin/rake db:create
RAILS_ENV=test bin/rake db:migrate
bin/rspec

Does it all work after a hard reset ?

1 Like

I have similar errors.

I’m seeing this error and I have a question.

2) ApplicationController#handle_theme selects the theme the user has selected
     Failure/Error: expect(controller.theme_ids).to eq([SiteSetting.default_theme_id])

       expected: [-1]
            got: []

       (compared using ==)
     # ./spec/requests/application_controller_spec.rb:314:in `block (3 levels) in <top (required)>'

debugging

spec expect to return SiteSetting.default_theme_id

in application_controller_spec.rb:314,

expect(controller.theme_ids).to eq([SiteSetting.default_theme_id])

SiteSetting.default_theme_id seems can be returned only if SiteSetting.default_theme_id != -1

in controllers/application_controller.rb#handle_theme method,

if theme_ids.blank? && SiteSetting.default_theme_id != -1
  theme_ids << SiteSetting.default_theme_id
end

SiteSetting.default_theme_id is set to -1 in /config/site_settings.yml

  default_theme_id:
    default: -1
    hidden: true

so, What am I missing?

can you help me?

Note: I am developing on Mac os, but I found post about this error only here, if this is not the good place, then please let me know. I’ll post it to other place like Beginners Guide to Install Discourse on macOS for Development


Update:

You should run:

redis-cli flushall
RAILS_ENV=test bundle exec rake db:drop db:create db:migrate

then test will pass.

but if you run:

redis-cli flushall
RAILS_ENV=test bundle exec rake db:drop 
RAILS_ENV=test bundle exec rake db:create db:migrate

Then you don’t have default_theme_id with value 2 in site_settings table which is should be to pass above test.

select * from site_settings
where name = 'default_theme_id';    // no row

And this is what I found for why this is happening

In discourse/lib/tasks/db.rake, there is

Rake::Task['db:create'].enhance(["db:force_skip_persist"] + reqs)

when run rake db:create db:migrate

  • Task db:force_skip_persist executed and GlobalSetting.skip_redis = true
  • Initializers loaded, and in initializers/005-site_settings.rb
if GlobalSetting.skip_redis?
    SiteSetting.provider = SiteSettings::LocalProcessProvider.new
    ...
end
  • provider.save does not hit db, so I don’t have default_theme_id.

when run rake db:drop db:create db:migrate

  • Task db:force_skip_persist NOT executed and GlobalSetting.skip_redis = nil because current step is db:drop
  • SiteSetting.provider = SiteSettings::LocalProcessProvider.new NOT executed when initializers load
  • so SiteSetting.provider is DbProvider
  • Initializers does not run anymore because once loaded. so does not set SiteSetting.provider = SiteSettings::LocalProcessProvider.new.

I converted the ruby install script at the beginning to arch / manjaro in case someone besides me has a use for it:
https://github.com/spirobel/install-rails

1 Like

This worked great for me, except for the fact that the logo in the upper left of the navigation bar is showing as a broken image. When I inspect the image I get this as the URL:
src=“http://localhost:3000/uploads/default/original/1X/1233b191a44c75447212ae753ac6446b436fae26.png
Which means that it’s trying to go to localhost:3000 even though I’m accessing the page remotely. Is there a way to fix this or otherwise configure the dev installation so that the image will use a relative URL?

ok found it - had to change the host_names in the config/database.yml file to be the IP address instead of the default which is “localhost”

Hello all ;D
For a production forum, is the better way installl over a docker with discourse ?

Greetings
Gerriet

Yep, that’s the easier install method for a production environment.

For production use discourse/INSTALL-cloud.md at master · discourse/discourse · GitHub

3 Likes

import backup database
now error
POST http://127.0.0.1:3000/session 403 (Forbidden)

Hi, when doing

I get the following error:
`

== Seed from /home/uwe/Software/discourse/db/fixtures/990_topics.rb
rake aborted!
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation “polls” does not exist
LINE 8: WHERE a.attrelid = ‘“polls”’::regclass
^
/home/uwe/Software/discourse/plugins/poll/plugin.rb:234:in schedule_jobs' /home/uwe/Software/discourse/plugins/poll/plugin.rb:454:inblock (2 levels) in activate!’
/home/uwe/Software/discourse/lib/plugin/instance.rb:316:in block in on' /home/uwe/Software/discourse/lib/discourse_event.rb:14:inblock in trigger’
/home/uwe/Software/discourse/lib/discourse_event.rb:13:in trigger' /home/uwe/Software/discourse/lib/post_creator.rb:233:intrigger_after_events’
/home/uwe/Software/discourse/lib/post_creator.rb:202:in create' /home/uwe/Software/discourse/lib/post_creator.rb:213:increate!’
/home/uwe/Software/discourse/lib/post_creator.rb:249:in create!' /home/uwe/Software/discourse/lib/seed_data/topics.rb:130:increate_topic’
/home/uwe/Software/discourse/lib/seed_data/topics.rb:16:in block (2 levels) in create' /home/uwe/Software/discourse/lib/seed_data/topics.rb:15:ineach’
/home/uwe/Software/discourse/lib/seed_data/topics.rb:15:in block in create' /home/uwe/Software/discourse/lib/seed_data/topics.rb:14:increate’
(eval):18:in block (2 levels) in run_file' /home/uwe/Software/discourse/lib/tasks/db.rake:61:inblock in ’

Caused by:
PG::UndefinedTable: ERROR: relation “polls” does not exist
LINE 8: WHERE a.attrelid = ‘“polls”’::regclass
^
/home/uwe/Software/discourse/plugins/poll/plugin.rb:234:in schedule_jobs' /home/uwe/Software/discourse/plugins/poll/plugin.rb:454:inblock (2 levels) in activate!’
/home/uwe/Software/discourse/lib/plugin/instance.rb:316:in block in on' /home/uwe/Software/discourse/lib/discourse_event.rb:14:inblock in trigger’
/home/uwe/Software/discourse/lib/discourse_event.rb:13:in trigger' /home/uwe/Software/discourse/lib/post_creator.rb:233:intrigger_after_events’
/home/uwe/Software/discourse/lib/post_creator.rb:202:in create' /home/uwe/Software/discourse/lib/post_creator.rb:213:increate!’
/home/uwe/Software/discourse/lib/post_creator.rb:249:in create!' /home/uwe/Software/discourse/lib/seed_data/topics.rb:130:increate_topic’
/home/uwe/Software/discourse/lib/seed_data/topics.rb:16:in block (2 levels) in create' /home/uwe/Software/discourse/lib/seed_data/topics.rb:15:ineach’
/home/uwe/Software/discourse/lib/seed_data/topics.rb:15:in block in create' /home/uwe/Software/discourse/lib/seed_data/topics.rb:14:increate’
(eval):18:in block (2 levels) in run_file' /home/uwe/Software/discourse/lib/tasks/db.rake:61:inblock in ’
Tasks: TOP => db:migrate
(See full trace by running task with --trace)`

Any idea how to fix?

Hey @JoshuaJoma,

Could you try instead of running bundle exec rake db:create db:migrate, split it into two separated commands?

bundle exec rake db:create
bundle exec rake db:migrate

I think this will solve that problem.

7 Likes

Dear Sir
While Installing Discourse I am stuck on
bundle exec rake autospace command . This command gets failures. I am sharing screenshots.

3 Likes