Skip to content
cibyr edited this page Sep 15, 2014 · 2 revisions

I have my beta stack deployed on Ubuntu 14.04 LTS running on a t2.micro EC2 instance, with Apache and mod_wsgi.

Dependencies

We need a few Ubuntu packages to get started:

sudo aptitude install git apache2 libapache2-mod-wsgi python-virtualenv python-dateutil python-mysqldb

Our source lives in ~/kegstarter:

cd
git clone https://github.com/cibyr/kegstarter.git

All the python dependencies live inside a virtualenv, created thusly:

mkdir ~/envs
cd ~/envs
virtualenv --system-site-packages kegstarter

To enter the virtualenv and install the dependencies:

. ~/envs/kegstarter/bin/activate
cd ~/kegstater
pip install -r requirements.txt

Django settings

Don't forget to create a local settings file, at the very least to set DEBUG = False and a unique SECRET_KEY:

vim kegstarter/local_settings.py

You should also configure your database backend here (I'm using a MySQL RDS instance):

# In local_settings.py
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mydb',
        'USER': 'your_db_username',
        'PASSWORD': 'some_secret_password',
        'HOST': 'mydb.whatever.us-west-2.rds.amazonaws.com',
        'PORT': 3306,
    },
}

Some other useful things to set are:

  • STATIC_ROOT = '/home/ubuntu/kegstarter/static/' (so django.contrib.staticfiles knows where to put stuff)
  • email config (I'm using SES with EMAIL_BACKEND = 'django_ses.SESBackend')
  • email addresses (ADMINS, DEFAULT_FROM_EMAIL and SERVER_EMAIL)

Apache config

Enable a few Apache modules:

sudo a2enmod wsgi
sudo a2enmod expires

Create a kegstarter.conf in /etc/apache2/sites-available:

<VirtualHost *:80>
ServerAlias kegstarter

Alias /favicon.ico /home/ubuntu/kegstarter/static/favicon.ico

Alias /static/ /home/ubuntu/kegstarter/static/

<Directory /home/ubuntu/kegstarter/static>
    Require all granted
    ExpiresActive On
    ExpiresDefault "access plus 1 week"
</Directory>

WSGIDaemonProcess kegstarter user=ubuntu group=ubuntu processes=2 python-path=/home/ubuntu/kegstarter:/home/ubuntu/envs/kegstarter/lib/python2.7/site-packages
WSGIProcessGroup kegstarter

WSGIScriptAlias / /home/ubuntu/kegstarter/kegstarter/wsgi.py

<Directory /home/ubuntu/kegstarter/kegstarter>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>    

</VirtualHost>

Disable the default site and enable kegstarter:

sudo a2dissite 000-default
sudo a2ensite kegstarter

Restart Apache:

sudo service apache2 restart
Clone this wiki locally