Over the last week, off and on, I’ve been looking at OpenShift, my company’s new platform-as-a-service offering. At first, seems interesting — you shove your code in a git repo, commit and it does stuff.
I decided to walk into this getting Django up and running on OpenShift, since there isn’t any documentation out there for that yet. Also in this blog post are intermixed my opinions on OpenShift. (As always, these are my personal opinions and don’t reflect the opinions of anybody I work for or with or around.)
The sidebar image on the Express page starts with sudo yum install rhc. Seems simple — and, in fact, made me think that the app was in Fedora. (Nope.)
I spent quite some time looking for a openshift-release RPM or openshift.repo file. There was a video on the front page, which involved a dev pasting his clipboard into a file called openshift.repo. My thoughts: “hell no I am not typing this off of a YouTube video.”
After registering an account and logging in, it did give me a URL to download an openshift.repo file, and then I was finally able to install rhc. Then I walked through the rest of the howto on that page:
$ rhc-create-domain -n ianweller -l [EMAIL] $ rhc-create-app -a djangotest -t wsgi-3.2.1
And down comes a git repo, populated with directories data, libs and wsgi. From here, I wrote .gitignore:
*.pyc *.pyo *.swp *~
I decided to install Django in a virtualenv. Keep in mind that the Express servers run RHEL 6 and therefore Python 2.6.5, so you need to start up the virtualenv from a Python 2.6.5 machine.
virtualenv -p /usr/bin/python2.6 --no-site-packages --distribute env ./libs/env/bin/easy_install django cd wsgi/ ../libs/env/bin/django-admin.py startproject myapp
Now we just have to configure the WSGI endpoint to load our virtualenv and serve up Django. Here’s what your wsgi/application should look like:
import os, sys here = os.path.dirname(os.path.abspath(__file__)) os.environ['PYTHON_EGG_CACHE'] = os.path.join(here, '..', 'data', 'python-eggs') virtualenv = os.path.join(here, '..', 'libs/env/bin/activate_this.py') execfile(virtualenv, dict(__file__=virtualenv)) sys.path.append(here) os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
Then git add everything, git commit, git push, and head on over to the domain you created. You should get a 404, because we haven’t configured urls.py yet.
If you do end up getting a 500 error, you’ll have to look at the httpd error_log, and you have to use rhc-snapshot to download the ENTIRE directory your application resides in. It’s a total pain in the ass, and I hope the OpenShift guys implement something like rhc-logwatch in the near future. (I know some of the OpenShift folks and I really like what they’re working on, so this isn’t meant as anything other than constructive criticism, and I know they know that.)
You’ll also note I don’t talk about databases at all in here. The easiest thing to do is to use a remote MySQL database, but if you need to use a local SQLite database with your Django app, have fun: even though there is a data/ directory in your git repo, it’s not meant for persistent data like a database file. If you run an rhc-snapshot, you’ll note there’s a data/ directory at the same level as your repo/ directory — this is where you’re supposed to put database files. It’s really difficult to run django-admin.py syncdb without having a shell. :)
But overall, OpenShift is definitely an interesting way to look at putting apps like Django out in the “cloud” (whatever that is), and was fun to play with.

This is becoming a theme with WSGI?
Can’t we just create a standard virtualenv GIT setup on Express and then ANY WSGI framework will work?
Thanks for the post though, I’ll try it soon.
J
Hi Ian,
Nice howto!
in your steps:
virtualenv -p /usr/bin/python2.6 –no-site-packages –distribute env
./libs/env/bin/easy_install django
cd wsgi/
../libs/env/bin/django-admin.py startproject myapp
did you mean to have the ‘env’ places in libs? following that virtualenv command line places it parallel to ‘libs’.
I would love to see the instructions for setting this up on Mac OSX.
I can’t find virtualenv on my OSX 10.6 with RHC tools and python installed.
actually nevermind. I read up on virtualenv and got the script. For some odd reason I thought it was one of the built in utilities at first.