Django on DreamHost with Passenger
Django has always been slow for me on Dreamhost thanks to FastCGI but not anymore. As of yesterday, I am using Passenger WSGI to launch my django applications and a significant performance increase is easily noted. For those wanting to use Passenger, here are some simple instrutions:
Warning: Passenger WSGI support is still just proof of concept. It can break, so be careful. I have not had any problems yet.
Setting up the account and domain
UPDATE: Brandon Carl (Spleeyah) has submitted a shell script to automate the task of entering the commands for setup. You can find the script here. After enabling passenger in the control panel and logging into ssh as explained below, just download the script, edit the three variables as required, upload to your base directory, chmod +x it, and run it.
Before we start installing anything, go into your DreamHost control panel and select the domain you want to install django on (or make a new one). You have to change the directory from domain to domain/public as this will serve as a base for static files. Then scroll down a little bit and enable Passenger.
Next, go to your manage users screen and select the user for the domain. Change the user from an FTP user to a Shell user if you haven’t done so already.
Finally, give DreamHost a few minutes to update their servers and then connect via ssh. For Mac and Linux users, open a terminal and type:
ssh domain -l username
If you are on Windows, Google the Netspace SSH client or just use PuTTY. Type in your password and get ready for some shell-based work. First let’s alter the environment:
echo 'PATH="$HOME/bin:$PATH"' >> ~/.bash_profile echo 'LD_LIBRARY_PATH=$HOME/lib/' >> ~/.bash_profile source ~/.bash_profile
This will alter your .bash_profile file so your home directory becomes part of your path.
Installing Python
Now, for an easy part, it’s time to download and install Python 2.6.2
wget http://python.org/ftp/python/2.6.2/Python-2.6.2.tgz tar -xzvf Python-2.6.2.tgz cd Python-2.6.2 ./configure --prefix=${HOME} make make install cd ~ rm -rf Python-2.6.2 rm Python-2.6.2.tgz
Not that bad. Just a few more installations left.
Installing SWIG
wget http://voxel.dl.sourceforge.net/sourceforge/swig/swig-1.3.40.tar.gz tar -xvzf swig-1.3.40.tar.gz cd swig-1.3.40 ./configure --prefix=${HOME} make make check make install cd ~ rm -rf swig-1.3.40 rm swig-1.3.40.tar.gz
Installing setuptools
Now for a useful script, setuptools. It will help us out really soon.
wget http://peak.telecommunity.com/dist/ez_setup.py python ez_setup.py rm ez_setup.py
Installing MySQLdb
I’m assuming that you will be using MySQL as a database backend. This will install the library needed for MySQL.
wget http://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.3b1.tar.gz tar -xvzf MySQL-python-1.2.3b1.tar.gz cd MySQL-python-1.2.3b1.tar.gz python setup.py install cd ~ rm -rf MySQL-python-1.2.3b1 rm MySQL-python-1.2.3b1.tar.gz
PIL (Python Imaging Library)
If you want to use any ImageField fields in your database or want to work with images, you have to have this or django will fail when syncing the database.
easy_install --find-links http://www.pythonware.com/products/pil/ Imaging
Setting up django
cd ~/domain rm -rfv ./* mkdir public svn co http://code.djangoproject.com/svn/django/trunk/ django_src easy_install django_src rm -rf django_src svn co http://code.djangoproject.com/svn/django/trunk/django mkdir public/media ln -s ~/domain/django/contrib/admin/media ~/domain/public/media/admin django-admin.py startproject project echo 'import sys, os' > passenger_wsgi.py echo 'INTERP = "/home/username/bin/python"' >> passenger_wsgi.py echo 'if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)' >> passenger_wsgi.py echo 'sys.path.append("/home/username/domain")' >> passenger_wsgi.py echo 'os.environ["DJANGO_SETTINGS_MODULE"] = "project.settings"' >> passenger_wsgi.py echo 'import django.core.handlers.wsgi' >> passenger_wsgi.py echo 'application = django.core.handlers.wsgi.WSGIHandler()' >> passenger_wsgi.py pkill python
Now visit domain in your webbrowser and you should see a page generated by django. Your media root is /home/username/domain/public/media/ and your media url is http://domain/media/.
Comments
Leave a comment Trackback