Friday, April 18, 2008

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

(permalink)
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",

(you may have to add mod_fastcgi in)



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


And add index.php if it's not already there:
index-file.names = ( "index.php", "index.html",
"index.htm", "default.htm" )





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 ./django-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


Add the following line to the settings.py file of the django project on the server:
FORCE_SCRIPT_NAME = ''

(this prevents redirects to django.fcgi)

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: , , , ,

Thursday, March 08, 2007

Gentoo & Mother

(permalink)
About 2 years ago I purchased a dell server, naming it mother...

Well as it turns out, I'm pretty happy with my setup. I've spent a LOT of time customizing / optimizing it (as usually is the case with Gentoo).

But there's just one small problem: I'm beginning to realize that I've come so far, I don't remember how I got here! I'm not sure how long it would take for me to rebuild everything if this server ever went down. I'm not even sure if I'd remember all the customizations / installs I've made, let alone HOW I made them...

So, in that light, I've decided to carefully "blog" all the changes I make to my server on its wiki page (http://bluwiki.com/go/BluWiki:Mother). Hopefully this will help me figure out what I've done, if I ever need to do it again. As an added benefit, it might also help others do the same...

Labels: