last updated: 4/5/2011
note that this stuff is always a moving target, much of this has been cribbed and combined from various blog posts. Much of the information was out of date from those, and if it is more than a couple months after the last updated date above, consider some of this likely to now be out of date.
Webfaction by default (at least on server I got) does not has virtualenv installed so we get virtualenv.py directly from it's github repo:
wget https://raw.github.com/pypa/virtualenv/master/virtualenv.py python virtualenv.py $HOME
edit .bashrc and/or .bash_profile such that $HOME/bin and $HOME/sbin are on your path. From now on, your python will be from the virtualenv we just set up previously. Verify that by:
which python ~/bin/python
Now that we have our virtualenv properly set up in our $HOME, let's properly install virtualenv into our virtualenv. I know this sound so meta but I hope you can get along with it:
pip install --egg virtualenv which virtualenv ~/bin/virtualenv
From now on to create new virtual environment, we'll just run virtualenv env_name
.
This is optional but I prefer to have this. Let's create pip config file to define some default parameters:
mkdir -p ~/.pip/cache cat - > ~/.pip/pip.conf # ~/.pip/pip.conf [global] download_cache=/home/ptone/.pip/cache # install as egg like easy_install did - new in pip-1.2. egg = true ^D
This will tell pip to cache the download so we can save some bandwidth and speed up package installation.
nginx and uwsgi can be shared among projects and do not need to be rebuilt for each site:
cd ~ mkdir tmp src bin sbin etc conf mylogs sock
http://nginx.org/en/download.html#stable_versions
cd src curl http://nginx.org/download/nginx-0.8.54.tar.gz | tar -xvz
http://projects.unbit.it/uwsgi/wiki/RunOnNginx
grab upload progress module:
http://github.com/masterzen/nginx-upload-progress-module
git clone https://github.com/masterzen/nginx-upload-progress-module.git
get uwsgi itself: I've found this latest version has compile errors on webfaction while this does not:
curl http://projects.unbit.it/downloads/uwsgi-0.9.6.8.tar.gz | tar -xz
build uwsgi:
cd uwsgi-x-x-x-x make -f Makefile.Py26 cp uwsgi $HOME/bin/
uwsgi module included by default in nginx since 0.8.40 so you do not need to specify it at configure time. Webfaction has sought to make the "logs" directory in your home folder owned by root - so we need to configure alternate log destinations.
build nginx:
cd ../nginx-0.8.54/ ./configure --add-module=../nginx-upload-progress-module/ \ --prefix=$HOME \ --error-log-path=$HOME/mylogs/nginx-error.log \ --lock-path=$HOME/mylogs/nginx.lock \ --pid-path=$HOME/mylogs/nginx.pid \ --http-log-path=$HOME/mylogs/nginx-access.log make make install
expect to see errors about deprecated sys_errlist: http://nginx.org/en/docs/sys_errlist.html
create custom port listening app:
cd webapps/<appname>/ virtualenv venv source venv/bin/activate
cd out to webapps/<appname> django-admin.py startproject test_project
get the django project settings and urls set up for admin to work
collect static files:
manage.py collectstatic
get project on python path:
cd venv/<site-packages> ln -s $HOME/webapps/<appname> .
start up nginx, note that it will not daemonize but can be started like this for testing:
nginx -p `pwd`/ -c ../test_project/etc/nginx.conf
create a wsgi.py file in project root:
import os os.environ['DJANGO_SETTINGS_MODULE'] = 'test_project.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
startup uwsgi, again, won't daemonize - you'll need two terminals to run both nginx and uwsgi in this test mode:
uwsgi -p 4 -s $HOME/sock/teststack_uwsgi.sock -H $HOME/webapps/teststack/venv/ --pythonpath $HOME/webapps/teststack/test_project -w wsgi
You should now be able to load up the Django-admin
create another custom port app in webfaction control panel
install supervisor with pip install supervisor
see supervisord.conf
see start_supervisor.sh
*/10 * * * * /home/ptone/bin/start_supervisor.sh start > /dev/null 2>&1 nohup start_supervisor.sh start