Friday, April 18, 2008

Django + Python + PHP(optional) + Lighttpd on Debian etch

Couldn't find any great howto, so here's how I did it:

It's a good idea to update apt-get:
apt-get update


I didn't want apache running on my system:
apache2ctl stop
update-rc.d -f apache2 remove


Install lighttpd:
apt-get install lighttpd


Uncomment these lines from /etc/lighttpd/lighttpd.conf:
server.pid-file = "/var/run/lighttpd.pid"
"mod_fastcgi",
"mod_rewrite",




If you want PHP support:
apt-get install php5-cgi


Add this line to the bottom of /etc/php5/cgi/php.ini
cgi.fix_pathinfo = 1


Add index.php:
index-file.names = ( "index.php", "index.html",
"index.htm", "default.htm" )


Add this to the bottom of vim /etc/lighttpd/lighttpd.conf:
fastcgi.server = (
".php" => ((
"bin-path" => "/usr/bin/php5-cgi",
"socket" => "/tmp/php.socket"
))
)





Python / Django support:

I like python 2.5.1:
apt-get install python2.5-dev
which python
cd to location of python binary
ls -lh (make sure python is a symlink)
rm python
ln -s python2.5 python


subversion to get django (also just a useful tool to have)
apt-get install subversion


Make a dir to hold all your install files:
mkdir /var/installers
cd /var/installers


Download & install:
wget http://peak.telecommunity.com/dist/ez_setup.py
python ez_setup.py


Get flup for python support:
wget http://www.saddi.com/software/flup/dist/flup-0.5-py2.5.egg
easy_install flup-0.5-py2.5.egg


Django:
svn co http://code.djangoproject.com/svn/django/trunk/ ./django-trunk/
cd ./djano-trunk
python setup.py install


Edit /etc/lighttpd/lighttpd.conf and change fastcgi.server to:
fastcgi.server = (
".php" => ((
"bin-path" => "/usr/bin/php5-cgi",
"socket" => "/tmp/php.socket"
)),
"/django.fcgi" => (
"main" => (
"host" => "127.0.0.1",
"port" => 9090, #set the port numbers to what-eva you want
),
),
"/admin.fcgi" => (
"admin" => (
"host" => "127.0.0.1",
"port" => 9091,
)
)
)

(notice php support - that's optional)


Add rewrite rules to lighttpd.conf:
url.rewrite-once = (
"^(/media.*)$" => "$1",
"^(/static.*)$" => "$1",
"^/favicon\.ico$" => "/media/favicon.ico",
"^(/admin/.*)$" => "/admin.fcgi$1",
"^(/.*)$" => "/django.fcgi$1"
)


Now make blank dummy files to prevent Lighttpd 404 errors:
vim /var/www/django.fcgi
vim /var/www/admin.fcgi


Now make a django project directory (www):
mkdir /var/django
cd /var/django


make a test project:
django-admin.py startproject testproject


start the project:

cd ./testproject
python manage.py runfcgi method=prefork host=127.0.0.1 port=9090 pidfile=django.pid

Note - using port 127.0.0.1 for runfcgi doesn't limit lighttpd to only that interface. It's used for communication between lighttpd & runfcgi

now test!
http://your_server_ip


Mysql support (haven't tested to see if this works):
I run my database on a separate server, if you don't, you'll need to set up mysql server as well. There are plenty of HOWTOS on that, try googling around.

apt-get install mysql-client

(will add config instructions later, once I do them)

Install MySQLdb, which lets python easily talk to mysql (haven't yet tested/configured this):
apt-get install python-mysqldb

Labels:

Sunday, April 06, 2008

An adventure in the fourth dimension...

I recently watched this insightful video of a presentation by Cliff Stoll at a recent TED conference.

I liked the video so much, I wanted to show my appreciation. I've decided to support Cliff's store - www.kleinbottle.com. I was going to buy a bottle - but why settle for that when you purchase an everyday wearable item... the Klein hat.

I have to admit... there is a bit of false advertising here. Cliff isn't actually selling Klein bottles, since it intersects itself (this creates an edge). Instead, you can think of it as a mobius strip (one side, one edge) - distorted to represent a Klein bottle in only 3 dimensions. A true Klein bottle needs a fourth division so that it does not intersect itself.

Come to think of it... since I can't observe the fourth spatial dimension... maybe this IS a true Klein bottle... hmmm... If so, I look forward the mind altering effects of wearing something that can only exist in four dimensions.

Either way, though, I'm pleased - it will at least make for some interesting looks as I walk around campus.

Labels: