This is my starting point for a new Django site, mixed and stirred from several public sources and spiced with my own enhancements.
I normally work with FeinCMS and its medialibrary, but sometimes also with Photologue and Schedule, this is reflected in my setups.
My webserver of choice is Nginx with gunicorn, since my virtual server is always low on memory. Setup for Apache with mod_wsgi and Nginx with fcgi is also provided.
- server OS: Debian/Ubuntu based Linux
- local OS: MacOS X (only some local settings are OSX specific)
- web server: Apache/mod_wsgi or Nginx/gunicorn or Nginx/fcgi
- Python version: 2.5+
- Django version: 1.2
- version control: Git
- deployment tool: Fabric
- local development database: SQLite3
- server database: MySQL or PostgreSQL
- database migration: South
- process control (optional): daemontools or supervisord
Django's startproject doesn't do enough. I'm a programmer, thus lazy, and try to reduce redundant work like repeating the same setup steps over and over. (DRY)
Just copying this generic project to a new site isn't ideal either, since general changes don't affect all dependent sites, but I got no idea how to do that.
- User creation isn't integrated in fabfile setup.
- Probably security holes - use at your own risk.
- I could also support runit, but I didn't want to replace init
- South still doesn't work for me, must overcome problems with several releases and multiple projects accessing the same Django app outside of virtualenvs
- copy generic_project
- replace all occurrences of "project_name" with your project name. this is also the webserver and database server username!
- replace all occurrences of "fiee.net" with your domain name.
- check the settings in fabfile.py, gunicorn-settings.py, settings.py, settings_local.py, supervisor.ini or service-run.sh
- if you use Nginx, change the internal port in nginx.conf (
fastcgi_pass 127.0.0.1:8001;
); I use "8 + last 3 numbers of UID" (UIDs start at 1000 on Debian) git init
, always commit all changesmanage syncdb
(initialize south)fab webserver setup
(once)fab webserver deploy
(publish new release - always last commited version!)
create user and sudo-enable it (I suggest via a group like wheel, but you can also add the user to sudoers):
adduser project_name adduser project_name wheel
create database user and database (schema) - I suggest to use makeuser.sh
mysql -u root -p # we installed MySQL without user interaction, so there's no root password. Set it! use mysql; update user set password=password('...') where user='root'; # create user and database for our project: create user 'project_name'@'localhost' identified by '...'; create database project_name character set 'utf8'; grant all privileges on project_name.* to 'project_name'@'localhost'; flush privileges; quit;
- Setup with Apache/mod_wsgi: http://morethanseven.net/2009/07/27/fabric-django-git-apache-mod_wsgi-virtualenv-and-p/
- Setup with Nginx: http://djangoadvent.com/1.2/deploying-django-site-using-fastcgi/
- Nginx configuration: http://wiki.nginx.org/NginxConfiguration
- Gunicorn configuration: http://gunicorn.org/configure.html
- logrotate: e.g. http://www.linux-praxis.de/lpic1/manpages/logrotate.html
- daemontools: http://cr.yp.to/daemontools.html
- supervisord: http://supervisord.org
- Fabric: http://docs.fabfile.org
- South: http://south.aeracode.org/ (Getting started: http://mitchfournier.com/?p=25)
- MPTT: http://code.google.com/p/django-mptt/ or http://github.com/matthiask/django-mptt
- FeinCMS: http://github.com/matthiask/feincms
- Schedule: http://wiki.github.com/thauber/django-schedule/ or http://github.com/fiee/django-schedule