Getting Django to work with uWSGI on Cherokee
This is a recipe to get uWSGI + Django working on Cherokee. It took me about a day of reading different blog posts, recipes and pulling my hair out so I am hoping that this post will save somebody the trouble.
Installing Cherokee
Keep in mind that depending on the Ubuntu version you might get a really old Cherokee package. To get a newer version just follow the steps on the following page:
Installing Cherokee from a PPAIf you are fine with an older version, just run the command below:
sudo apt-get install cherokee
Django project setup
I will not go in great detail here. Just create a normal Django project with two extra, empty files inside of it: django_wsgi.py and uwsgi.conf.
/home site/ dev/ __init__.py django_wsgi.py manage.py settings.py urls.py uwsgi.conf
Creating the uwsgi.conf file
<uwsgi> <pythonpath>/home/site</pythonpath> <app mountpoint="/"> <script>dev.django_wsgi</script> </app> </uwsgi>Three important points:
- File needs to be in the Django project's folder
- pythonpath is the path to the Django project
- script is a module, in relation to the pythonpath above. Do not include the .py.
Creating the django_wsgi.py file
Create the djano_wsgi.py file with the below content making sure to replace the dev.settings module with the appropriate name for your Django project.
import os import sys os.environ['DJANGO_SETTINGS_MODULE'] = 'dev.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
Setting up uWSGI on Cherokee
Now, all that remains is to setup a rule for your virtual server, by clicking on the 'vservers' icon at the top of the Cherokee Admin. Please see the following screen shot as a reference:
Click on 'Rule Management' then click on 'New' (to add a new rule), then select the 'Platforms' category, then uWSGI as shown here:
Follow the wizard and then enter the path to the uwsgi.conf file as shown in the following screen shot:
Leave the appmount value the same as in the uwsgi.conf file, and press 'Create'.
This will create the 'information source' (the uWSGI interpreter) that will be used as the handler for that specific directory. Now make a change to the interpreter's arguments by going to the Sources link at the top and clicking on the newly created information source on the left side of the page. Look for the 'Interpreter' field (might need to scroll down a bit) and then remove the -H argument like so:
This is the command that should be in the 'Interpreter' field (make sure to replace the IP + port + uwsgi.confg file path to the appropriate values):
/usr/bin/uwsgi -s 127.0.0.1:45023 -t 10 -M -p 1 -C -x /home/site/dev/uwsgi.conf
Common Issues
- uwsgi application not found
Make sure that the pythonpath is correctly set in the uwsgi.conf file. Also make sure that the script element is set to the Python module (project.django_wsgi and not python.django_wsgi.py).