There are several tricks that can help when you are setting up a staging server.
A staging server is essentially a clone of a production site. It also resides on a server, and functions identically. It runs inside a Docker container, just as a normal Discourse site does.
It exists to give you a place to try risky things out, or to trial things that you cannot easily hide from your users. It is very useful for trialling adverts using the Discourse Ad Plugin, or if you want to do something funky like a forum import or merge.
This is in contrast to a development server, which typically runs in an easily accessible (and sandboxed) place so that a developer can tinker with the code safely.
Everything that you need for a standard self-hosted install
If you have S3 backups setup, your life will be a whole lot easier
- otherwise you’ll need a way to move large files into and out of a server via SSH
Typically in a virtual Ubunto server hosted on Digital Ocean, but you can use whatever you are comfortable with.
Via this guide (or maybe via dashboard.literatecomputing.com). I recommend using ‘junk’ email credentials (you don’t need or want email to work).
Set yourself up an admin account from the command line. This skips the need to authenticate via email.
./launcher enter app rake admin:create
This isn’t strictly necessary except for testing the install as you can restore from backup from the command line.
You might like to make a copy of the original app.yml (I call mine
app.vanilla.yml) which you can revert to if you stuff things up
At the bottom of the
envsection add these lines:
## Staging server specific settings DISCOURSE_AUTOMATIC_BACKUPS_ENABLED: false DISCOURSE_LOGIN_REQUIRED: true DISCOURSE_DISABLE_EMAILS: 'yes' DISCOURSE_S3_DISABLE_CLEANUP: true DISCOURSE_ALLOW_RESTORE: true
If you have S3 (or similar) backups configured then add these too (with your settings from the main site)
## S3 Configuration DISCOURSE_S3_ACCESS_KEY_ID: 'your_key' DISCOURSE_S3_SECRET_ACCESS_KEY: 'your_secret' DISCOURSE_BACKUP_LOCATION: 's3' DISCOURSE_S3_BACKUP_BUCKET: 'your_backups_location' DISCOURSE_S3_REGION: 'your_s3_region' DISCOURSE_S3_DISABLE_CLEANUP: true
and if you also are doing S3 uploads:
DISCOURSE_ENABLE_S3_UPLOADS: true DISCOURSE_S3_UPLOAD_BUCKET: 'your_uploads_location'
You might like to add the same plugins that you have on your production site while you are there.
Do a rebuild
./launcher rebuild app
You’ve now got a staging server that is connected to your S3 backups (but won’t overwrite them), is easy to restore to, and that is unable to email anyone under any circumstances. Perfect!
You can restore a fresh backup to the staging server and go to town. If you don’t like what you have, you simply restore it again.
If you leave your staging server ‘on’ for prolonged periods, you do risk it being indexed by Google, and having your users accidentally login to it instead. As their credentials are a clone of your production site, this is very possible.
A simple way to mitigate these two things is to simply turn Discourse off:
./launcher stop app
And to turn it back on so you can use it:
./launcher restart app
You’ll have to make sure that you update/rebuild both it and your production site at the same time if you want to ensure that things remain aligned from the plugin and code point of view. Same goes for app.yml changes.
If you don’t use S3, you’ll have to manually move backups between servers. And they are big!
If you want a staging server, then you should populate it with your actual data from your actual forum via a
Restore. Sometimes it is your particular data that is causing the issue, and testing your forum with some other set of data can give you a sense of false hope.
If what you want is a test server to see what Discourse is like, though, you might want to check things out with some fake data, and if you do, you can do this:
./launcher enter app ALLOW_DEV_POPULATE=1 bundle install ALLOW_DEV_POPULATE=1 rake dev:populate
This will seed your forum with some fake data so that you can see what things look like with whatever themes and plugins you want. If you haven’t started your forum yet, this will give you some idea what things are likely to look like.
While your account username / password from your main site should also work just fine in the staging site, it isn’t so pretty with 2FA. If you have an issue, turn off 2FA:
./launcher enter app rake users:disable_2fa[<USERNAME>]