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

384 views
Skip to first unread message

ivan.k...@gmail.com

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

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

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.
http://articles.slicehost.com/2007/12/3/ubuntu-gutsy-django-installation


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 http://peak.telecommunity.com/dist/ez_setup.py
# python ez_setup.py


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 http://www.saddi.com/software/flup/dist/flup-0.5-py2.5.egg
# 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
libpcre3


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: http://dev.mysql.com/doc/refman/5.0/en/adding-users.html
# 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'
IDENTIFIED BY 'password' WITH GRANT OPTION;


14. Create a new database. More here: http://dev.mysql.com/doc/refman/5.0/en/create-database.html
mysql> CREATE DATABASE [databaseName];


15. Install Django
# cd /home/installers
# svn co http://code.djangoproject.com/svn/django/trunk/
# cd trunk
# python setup.py install


16. Configure Django. Set your settings.py 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 = (
"mod_access",
"mod_alias",
"mod_rewrite",
"mod_fastcgi",
"mod_accesslog",
"mod_status",
)
server.document-root = "[path to your public_html directory]"
server.indexfiles = ( "index.html", "index.htm" )
server.port = [some port]
server.bind = [your ip]
server.pid-file = "[path to pid file]"
fastcgi.server = (
"/django.fcgi" => (
"main" => (
"host" => "127.0.0.1",
"port" => [django port],
)
),
"/admin.fcgi" => (
"admin" => (
"host" => "127.0.0.1",
"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 manage.py runfcgi method=prefork host=127.0.0.1 port=3033
pidfile=django.pid


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: http://235.46.34.256:3456/


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
recommend.

Ivan Kirigin
www.kirigin.com
Reply all
Reply to author
Forward
0 new messages