HowTo: Django + SliceHost + lighttpd + fcgi + flup + MySQL + MySQLdb

Skip to first unread message

Jan 8, 2008, 3:21:44 PM1/8/08
to Django users

I just setup a new Slicehost slice, built with Ubuntu 7.10 Server
I'm using Django with Lighttpd, flup for fastcgi, mysql with python-

Here is the software I needed. I left off a few bits, but hopefully
you'll find this useful.
Feel free to post this on your site.

Some of the instructions here were useful too.

1. Get a new slice. Minimum size is fine, but 256MB might be small for
memory. Select Ubuntu 7.10 (gutsy)

2. Your slice will be rebuilt, login and change the root password
$ ssh ro...@your.ip.add.ress
[ enter given password ]
# passwd
Enter new UNIX password: [ enter new password ]
Retype new UNIX password: [ enter new password again ]
passwd: password updated successfully

3. The slice comes pre-installed with Python 2.5.1
# python
Python 2.5.1 (r251:54863, Oct 5 2007, 13:50:07)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

4. Get extra tools for easy installation. I like to put all my eggs
and tarballs in one basket. Wget grabs files from a url.
# mkdir /home/installers
# cd /home/installers
# wget
# python

5. Update your apt-get. You can add more sources too.
# apt-get update

6. If you need to build with the python development headers, do
# apt-get install python-dev

7. Install Subversion so we can get latest release of Django
# apt-get install subversion

8. Install a development environment and curl is useful :)
# apt-get install build-essential curl

9. Install flup for fastcgi support for Django & lighttpd
# wget
# easy_install flup-0.5-py2.5.egg

10. Install lighttpd
apt-get install lighttpd

11. Install MySQL
apt-get install mysql-client mysql-server libmysqlclient15-dev

12. Install MySQLdb, which lets python easily talk to mysql
apt-get install python-mysqldb

13. Create a new MySQL user for django. When prompted for a password,
just press enter. More here:
# mysql -u root -p
Enter password: [just press enter]
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.45-Debian_1ubuntu3.1-log Debian etch distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost'

14. Create a new database. More here:
mysql> CREATE DATABASE [databaseName];

15. Install Django
# cd /home/installers
# svn co
# cd trunk
# python install

16. Configure Django. Set your to point to local host,
using mysql, with the name/pass/dbName you set in (13) & (14)

17. Configure Lighttpd. You'll want to setup fcgi to point to
localhost and a port that Django will use. A part of your
lighttpd.conf will probably look like this as follows. Note the
server.port can be whatever you want, probably best to setup Apache to
proxy Lighttpd.
server.modules = (
server.document-root = "[path to your public_html directory]"
server.indexfiles = ( "index.html", "index.htm" )
server.port = [some port]
server.bind = [your ip] = "[path to pid file]"
fastcgi.server = (
"/django.fcgi" => (
"main" => (
"host" => "",
"port" => [django port],
"/admin.fcgi" => (
"admin" => (
"host" => "",
"port" => [django admin port],
url.rewrite-once = (
"^(/media.*)$" => "$1",
"^(/static.*)$" => "$1",
"^/favicon\.ico$" => "/media/favicon.ico",
"^(/admin/.*)$" => "/admin.fcgi$1",
"^(/.*)$" => "/django.fcgi$1"

18. Run lighttpd
# lighttpd -f lighttpd.conf

19. Run django. Let's assume you are in your project directory. To get
the fcgi talking to Django, use local host and port used in the
fcgi.server configuration in (16)
# python runfcgi method=prefork host= port=3033

20. You can test this without setting up the Apache proxy by pointing
your browser straight to the server IP and server.port you selected.
With random numbers, it might look like this:

21. That's it! You're done!

Post corrections here. If someone wants to delve into anything
missing, go ahead. I sent this in to the Slicehost guys too, and
they'll probably post it. It's a wonderful service that I can highly

Ivan Kirigin
Reply all
Reply to author
0 new messages