# Programmatic configuration of a new Discourse site

**URL:** https://meta.discourse.org/t/programmatic-configuration-of-a-new-discourse-site/24499
**Category:** Self-hosting
**Created:** [January 27, 2015, 10:11pm UTC](https://meta.discourse.org/t/programmatic-configuration-of-a-new-discourse-site/24499 "2015-01-27T22:11:51Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![ahuling](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ahuling/32/115535_2.png) [@ahuling](https://meta.discourse.org/u/ahuling)
#### Post date: [January 27, 2015, 10:11pm UTC](https://meta.discourse.org/t/programmatic-configuration-of-a-new-discourse-site/24499/1 "2015-01-27T22:11:51Z")

</div>

Is it possible to programmatically configure a new site via the API?

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [January 27, 2015, 10:39pm UTC](https://meta.discourse.org/t/programmatic-configuration-of-a-new-discourse-site/24499/2 "2015-01-27T22:39:32Z")

</div>

What do you mean by “configure a new site”?

---

<div class="post-metadata">

### Author: ![ahuling](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ahuling/32/115535_2.png) [@ahuling](https://meta.discourse.org/u/ahuling)
#### Post date: [January 28, 2015, 3:17pm UTC](https://meta.discourse.org/t/programmatic-configuration-of-a-new-discourse-site/24499/3 "2015-01-28T15:17:57Z")

</div>

I’m most interested in setting up admin users, running through the steps in the [Admin Quick Start Guide](https://github.com/discourse/discourse/blob/master/docs/ADMIN-QUICK-START-GUIDE.md), and configuring SSO.

---

<div class="post-metadata">

### Author: ![elberet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elberet/32/122404_2.png) [@elberet](https://meta.discourse.org/u/elberet)
#### Post date: [January 29, 2015, 6:28pm UTC](https://meta.discourse.org/t/programmatic-configuration-of-a-new-discourse-site/24499/4 "2015-01-29T18:28:58Z")

</div>

If you’re fluent in Ruby, you can change pretty much everything by simply loading up the Discourse app in a Ruby script:

```plaintext
require "/path/to/discourse/config/environment"
SiteSetting.must_approve_users = true
u = User.new(username: "admin", email: "admin@example.com", ...)
u.save!

```

Obviously, this script must live and be executed inside Discourse’s docker container. Also, note that the first line loads the _entire_ Discourse app into the script and is fairly time consuming.

---

<div class="post-metadata">

### Author: ![ahuling](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ahuling/32/115535_2.png) [@ahuling](https://meta.discourse.org/u/ahuling)
#### Post date: [January 29, 2015, 6:55pm UTC](https://meta.discourse.org/t/programmatic-configuration-of-a-new-discourse-site/24499/5 "2015-01-29T18:55:52Z")

</div>

Perfect – thank you @elberet!

---

<div class="post-metadata">

### Author: ![renoirb](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/renoirb/32/114880_2.png) [@renoirb](https://meta.discourse.org/u/renoirb)
#### Post date: [April 30, 2015, 2:33am UTC](https://meta.discourse.org/t/programmatic-configuration-of-a-new-discourse-site/24499/6 "2015-04-30T02:33:31Z")

</div>

I’ve come across the same requirement to programatically configure Discourse configuration. Unfortunately for me, i’m not fluent in Ruby. There must be some magic somewhere that I didn’t get yet.

In [_discourse_ code, at `config/site_settings.yml`](https://github.com/discourse/discourse/blob/master/config/site_settings.yml) which would be nice we could superseed via configuration files. So far, I know we can do a few things via a file we install from [_discourse\_docker_ from `samples/standalone.yml`](https://github.com/discourse/discourse_docker/blob/master/samples/standalone.yml), and that we can extend keys from [_discourse_ at `config/discourse_defaults.conf`](https://github.com/discourse/discourse/blob/master/config/discourse_defaults.conf).

Is there a way to do the same with _site\_settings.yml_?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [April 30, 2015, 2:39am UTC](https://meta.discourse.org/t/programmatic-configuration-of-a-new-discourse-site/24499/7 "2015-04-30T02:39:44Z")

</div>

Site settings are all in the database so you can easily set overrides by using our object model.

---

<div class="post-metadata">

### Author: ![renoirb](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/renoirb/32/114880_2.png) [@renoirb](https://meta.discourse.org/u/renoirb)
#### Post date: [April 30, 2015, 2:46am UTC](https://meta.discourse.org/t/programmatic-configuration-of-a-new-discourse-site/24499/8 "2015-04-30T02:46:13Z")

</div>

I was hoping there was a way to inject settings so that I dont need to use database to do it. If there is none, its OK 🙂

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [April 30, 2015, 2:49am UTC](https://meta.discourse.org/t/programmatic-configuration-of-a-new-discourse-site/24499/9 "2015-04-30T02:49:00Z")

</div>

not following are you looking to provision 1000s of sites 🙂

you can change site settings in the UI, if you must pre-populate site settings you can add hook that runs post migration that forces a setting. you can not change defaults.

---

<div class="post-metadata">

### Author: ![renoirb](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/renoirb/32/114880_2.png) [@renoirb](https://meta.discourse.org/u/renoirb)
#### Post date: [April 30, 2015, 10:32pm UTC](https://meta.discourse.org/t/programmatic-configuration-of-a-new-discourse-site/24499/10 "2015-04-30T22:32:17Z")

</div>

In fact i’m more interested in ways to [declare which authorize URL](https://github.com/discourse/discourse/blob/master/config/site_settings.yml#L531) I can go against for S3 settings. And it seems that if I don’t use Amazon AWS, I can’t do it. (maybe I missed the config key).

On a related note, here’s [how I provision an app only container](https://meta.discourse.org/t/separating-redis-clusters-what-s-sent-into-redis-cached-views-sessions-both/28156/2).
