Skip to content

Instantly share code, notes, and snippets.



Last active Dec 25, 2015
What would you like to do?
Setting application environment variables on production servers

A great tool is envdir

apt-get install envdir
mkdir /etc/mysite.d/env
echo "postgres://postgres:@localhost:5432/mysite" > /etc/mysite.d/env/DATABASE_URL
echo "s3ce3t K3Y" > /etc/mysite.d/env/SECRET_KEY
echo "/srv/www/mysite/static" > /etc/mysite.d/env/STATIC_ROOT
echo "mysite.settings" > /etc/mysite.d/env/DJANGO_SETTINGS_MODULE

etc. etc. for all variables to set. Then prefix all commands with envdir /etc/mysite.d/env. If you have a site deployed in a virtualenv located in /srv/www/mysite/venv, here is how to run gunicorn to serve this site:

envdir /etc/mysite.d/env /srv/www/mysite/venv/bin/gunicorn mysite.wsgi

And to run a management command:

envdir /etc/mysite.d/env /srv/www/mysite/venv/bin/python migrate --list

It's a bit of typing for cron entries and initscripts / supervisor scripts but works very well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.