Deployment with NginX, Flup and Django

In first post I mentioned I would cover Byteflow installation and deployment process in next post. That wasn’t actually true because this third post :) I have developed with PHP for years and have recently tried out some developing with Python. Python frameworks that I have explored are Django, Web2py and Pylons. I started with Django and really like it. Also Pylons looks really nice. Web2py has some nice ideas but the concept feels somehow weird (development happens on browser). When I had an idea of this blog I had feeling that I would get it up and running in shortest time if I use Django. Then I started look for ready to use Django blog app and found Byteflow. Installation on local machine was quite easy but installation on server I had some problems.

Preparing the server

First I have to say that this isn’t complete tutorial how to install and deploy Byteflow. More like I will describe main steps and explain what problems I met. Maybe this post will help someone how will have same kind of problems. First I installed blog engine on my laptop and created theme with local version. On my laptop I used Django’s built-in server. Installation process was quite simple step and Byteflow’s documentation was enough for complete that. When my blog was ready for publishing it was time deploy it on server. I had this server up and running with NginX webserver so I had to install all python stuff and Django to serve this blog. I installed setuptools, virtualenv and flup from Ubuntu repository that way they will keep up to date with aptitude.

aptitude install python-setuptools python-virtualenv python-flup

I am not really fan of how python handles installed module on site-packages so I use virtualenv. I created own virtualenv for blog.

mkdir /var/www/python
cd /var/www/python
virtualenv blog

After that I installed Django, python-openid and beatifulsoup with easy_install to that virtualenv. This way and don’t mess global site-packages dir with these applications.

cd blog
source bin/activate
easy_install django
easy_install python-openid
easy_install beatifulsoup

Next I configured NginX. Yoy can find example configuration for example from Ubuntu Wiki.

Then it was time to start fcgi process, which will serve the blog.

/var/www/python/blog/bin/python /var/www/python/blog/byteflow/manage.py runfcgi host=127.0.0.1 port=8080 &

Debugging with Flup

Of course everything doesn’t happen as easy as it is planned. I got only stupid Internal Server error and nothing to any error logs. This is where I think my PHP setup beats Python setup but reason for that isn’t in Python self. I find out it was Flup that was suppressing errors. I had error on my settings.py and Django error handler wasn’t initialized yet so Flup was handling error and it only suppressed errors.

That was really annoying and I had to google quite long before I found solution how to find out what was the problem. On this stage I didn’t knew it was settings.py, which was causing error. Finally I found some help from Stack Overflow. When I enabled debugging on Flup I had to start fcgi with outlog and errlog parameters to see Flups messages.

/var/www/python/blog/bin/python /var/www/python/blog/byteflow/manage.py runfcgi host=127.0.0.1 port=8080 outlog=/var/log/fastcgi.output errlog=/var/log/fastcgi.error

After that I saw from fastcgi.error file that I had typo on database path. Ouch, small typo and so much pain. Of course next time it’s maybe little bit easier when I now have some experience from FCGI and Flup. I also read that the author of Flup hates FCGI and doesn’t even use Flup anymore but I don’t any other method to serve Django with NginX that FCGI and Django’s FCGI implementation depends heavily on Flup.

So, what I have learned from this (other than Flup sucks). Python application deployment isn’t as easy as PHP application deployment and I think that is one reason for PHP’s success, but when you know how to turn debug on from Flup python application deployment isn’t much more complicated.

Add post to: Delicious Reddit Slashdot Digg Technorati Google
(already: 1) Comment post

Comments

No comments for this post

Required. 30 chars of fewer.

Required.

Login

login