How to change a site setting via the Console

AI-generated summary

The discussion on how to change a site setting via the Console revolves around troubleshooting and resolving issues with Discourse settings, particularly enable_sso and force_https. Users encountered login problems after enabling SSO, with solutions involving running bundle exec rails c to modify settings directly, such as setting SiteSetting.enable_sso = false zogstrip or SiteSetting.enable_local_logins = true riking. Some users faced errors like Could not locate Gemfile ewanly or PostgreSQL authentication issues ewanly, which were resolved by entering the container via ./launcher enter app. Alternative methods include using rails db to update the database directly, such as changing language settings Alavi1412 or bypassing regex validation Dannii. Users also shared tips for restarting the app, like using ./launcher restart app zogstrip or using rails runner for quick updates Artem_Vasiliev.

So while investigating
https://meta.discourse.org/t/logout-menu-item/32731/21?u=cpradio

I enabled SSO, then logged out (yikes!), and now I can’t log back in, as it wants me to use SSO to do so :frowning:

How can I disable the enable_sso site setting so I can get back into my local environment?

in your /discourse

bundle exec rails c
SiteSetting.enable_sso = false

:wink:

Ah, I did it a different route, but yours is easier. :smile:

I ended up doing

s = SiteSetting.find_by(name: 'enable_sso')  
s.value = 'f'  
s.save!  

I was just about to post that here and saw your response. Thanks! Now I can at least constantly get back to a good state between tests :smile: (or maybe I should setup an actual SSO…)

For future reference, visit /u/admin-login

Yeah just use /users/admin-login

I did

SiteSetting.enable_sso = false

But I ended up with this login form:

How can I log-in please?

Looks like you have no login methods available.

Do SiteSetting.enable_local_logins = true .

Yes!

Thank you very much!

After running : “bundle exec rails c”
I’m getting an error : “Could not locate Gemfile”

How to fix it?

Are you running this from inside your container (./launcher enter app)?

No I wasn’t :blush: since its wasn’t mentioned. Sorry a lot of things to learn yet :alien:

So I did these commands:

cd /var/discourse
./launcher enter app

then
bundle exec rails c

and I’ve got the following errors:

URGENT: FATAL: Peer authentication failed for user “discourse”
Failed to initialize site default
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in initialize': FATAL: Peer authentication failed for user "discourse" (PG::ConnectionBad) from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in new’
from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect’

…
… many folders list
…

I did ./launcher rebuild app and tried again. The same errors!


After I’d pissed of these problems. I did restored my droplet from a previous snapshot I had and started from scratch.

I did enabled FORCE_HTTPS without a problem.

Can we change the discourse language in bundle exec rails c console?
How can we change the language of our site to english?

changing language can be done in database in site_settings column.
just search the current language and replace new language:
below code change language from Farsi to english:
UPDATE site_setting SET value = 'en' where value = 'fa_IR'
I have typed this code after typing : rails db

I had a problem with the force_https option (couldn’t login after enabling it). I fixed it by doing:

cd /var/discourse/
./launcher enter app
rails c
[1] pry(main)> SiteSetting.force_https = false
=> false

I believe a setting regex needs updating, and want to test with a new value, but when I go SiteSetting.key = value it blocks me because of the regex. Is there a way to force update a value even if it doesn’t match the setting’s regex?

Edit: this worked, though be very careful!

cd /var/discourse/
./launcher enter app
rails db
discourse=> update site_settings set value='newvalue' where name='settingname';

And then exit out, and restart the app:

./launcher stop app
./launcher start app

./launcher restart app is slightly faster to restart the app :wink:

Just in case, here’s a shell script oneliner not requiring to restart Discourse: bundle exec rails runner "SiteSetting.set('enable_sso', false)". It works just like it would from Discourse Admin UI.