django on Openshift
Openshift is a new app hosting service from RedHat which offers a great free package. Till now I’ve used Heroku to host some apps and its great but it doesn’t provide any free database (well it does but you’ll have to enter your credit card details which in India few people have). Also the filesystem of heroku is such that it refreshes every 24hrs deleting every thing except the repo. So heroku is great for testing but hosting something with somesort of a database is not possible unless you pay.
In comes Openshift to the rescue. It provides a 1GB filesystem which doesnot refresh and a free database which is quiet generous. So right now I’m trying to host a django app on Openshift and I’ll document the steps that I take here.
#Steps:
1.Create a python app using the web interface.
Or using the command line:
2.Clone the source code.
Can get git url form your apps web console.
3.Locally create a django app.
Now you can modify the source, but its better to start from scratch. So ceate a new django app:
4.Install gunicorn and set it up:
Follow the instructions on the gunicorn website to setup gunicorn:
5.Copy reqired files from cloned source.
Copy the following from the cloned source of your Openshift app to the root of the django app: .openshift
, setup.py
, requirements.txt
6.Generate the requirements file.###
7.Ceate the app.py file
OpenShift runs this app.py file as the entry point into the app. We are using gunicorn so we need to start gunicorn server from here. To do this follow the instructions in the following links:
The final app.py file will look something like this
8.Commit all the changes and push to Openshift
Commit all files in mydjangoapp
to a git repo.
Then push this repo to Openshift
9.Adding environment variables if necessary
Follow the instructions here
And that should do the job.