I mentioned in my previous Django post that I'd write about hosting my new Django blog site on Webfaction. As promised, here it is.
I had some problems deploying my first site at Webfaction. First I got an error about pysqlite. I tried using Postgresql, and then I got an error about something else when trying to do a
python2.5 manage.py syncdb. I think that they didn't set me up with a current Django installation. Luckily the support was prompt and helpful. I ended up reinstalling the Django application from the Webfaction Control Panel. Here are the steps I took to deploy my less than fledgling site.
Sign up for a shared hosting plan at Webfaction
I signed up for Webfaction's lowest plan at $9.50/month with no commitment. Here is their pricing plans.
Play with new account
I got a welcome email within 24 hours with the details about my account.
sofeng.webfactional.com was a domain name which they provided. Visiting this address in my browser showed my the It worked! Django new project page. I also ssh'd into my shell account by using
ssh sofeng.webfactional.com. The OS is CentOS5 which, I think, is based on Red Hat. It was a little different than the Ubuntu that I'm used to. I copied some of my configuration files over to make me feel more at home. On my home machine:
$ scp .bashrc firstname.lastname@example.org: $ scp .screenrc email@example.com: $ scp .emacs firstname.lastname@example.org:
Note, if your Webfaction account is set up properly with Django, you shouldn't need to take these steps. Like I mentioned earlier, I had some problems with my Django installation. So I ended up reinstalling Django. It's not as hard as it sounds-- just a few clicks in the Control Panel.
- In my browser, I went to the Webfaction Control Panel at https://panel.webfaction.com/.
- Under "> Domains / websites", I selected "Applications".
- I removed my current Django installation by clicking the icon with the minus sign.
- I clicked the icon with the plus sign to add a new application.
- I filled in the following information:
"Name:": djangoThen I clicked the "Create" button.
"App type:": Django 0.96.2/mod_python 3.3.1/Python 2.5
- Finally, I needed to specify which URL path I want to use with my Django application.
Under "> Domains / websites", I selected "Websites".
- I selected the icon with the pencil to edit the website settings.
- In the "Site apps:" section, I selected the icon with the plus sign to add a new App and path. I selected "django" as my "App:" and entered "/" (without the quotes) in the "URL path" field. Then I clicked "Update".
- After a couple minutes, I was able to view the Django It worked! page at
Upload my project
- The welcome message recommends using
sftp, but I used
rsyncinstead because I'm more familiar with it:
sofeng@home:~ $ rsync -avz ~/src/django/myblogsite email@example.com:webapps/django
- I ssh'd into my webfaction shell account:
sofeng@home:~ $ ssh firstname.lastname@example.org
- I set the PYTHONPATH. (I actually put this in my .bash_profile)
sofeng@web36:~ $ export PYTHONPATH=$HOME/webapps/django
sofeng@web36:~ $ cd ~/webapps/django/myblogsite
- I tried to do a
python2.5 manage.py syncdb, but got a database error:
Traceback (most recent call last): File "manage.py", line 11, in
execute_manager(settings) File "/home/sofeng/webapps/django/lib/python2.5/django/core/management.py", line 1672, in execute_manager execute_from_command_line(action_mapping, argv) File "/home/sofeng/webapps/django/lib/python2.5/django/core/management.py", line 1571, in execute_from_command_line action_mapping[action](int(options.verbosity), options.interactive) File "/home/sofeng/webapps/django/lib/python2.5/django/core/management.py", line 504, in syncdb cursor = connection.cursor() File "/home/sofeng/webapps/django/lib/python2.5/django/db/backends/sqlite3/base.py", line 58, in cursor self.connection = Database.connect(**kwargs) sqlite3.OperationalError: unable to open database file
- I needed to edit my
settings.pyfile. I changed the following lines:
DATABASE_NAME = '/home/sofeng/webapps/django/myblogsite/mydatabase.sqlite3' TEMPLATE_DIRS = ( '/home/sofeng/webapps/django/myblogsite/templates', )
- I tried
python2.5 manage.py syncdbagain:
$ python2.5 manage.py syncdb Loading 'initial_data' fixtures... No fixtures found.It worked.
- The next step was to set up the Apache configuration.
$ cd ~/webapps/django/apache2/conf
- I edited the following line in
SetEnv DJANGO_SETTINGS_MODULE myblogsite.settings
- Then I restarted the Apache server:
- In my browser, I went to
http://sofeng.webfactional.com/myview1, but got an error:
ImportError at /myview1/ No module named blog.models Request Method: GET Request URL: http://sofeng.webfactional.com/myview1/ Exception Type: ImportError Exception Value: No module named blog.models Exception Location: /home/sofeng/webapps/django/lib/python2.5/django/core/urlresolvers.py in _get_urlconf_module, line 177
- I guess I need my project on the Python path. I edited the following line in
PythonPath "['/home/sofeng/webapps/django/myblogsite', '/home/sofeng/webapps/django', '/home/sofeng/webapps/django/lib/python2.5'] + sys.path"
- Then I went back to
http://sofeng.webfactional.com/myview1and saw my page. Success!
Update 6/7/2008: By default Webfaction doesn't come with Mercurial installed, but they do allow you to do a user installation. I decided it would be useful to have Mercurial so I could pull and merge changes with greater control. Here are my steps.This will do a user-wide (as opposed to system-wide) installation of Mercurial in
sofeng@home:~/incoming $ wget http://www.selenic.com/mercurial/release/mercurial-1.0.1.tar.gz
sofeng@home:~/incoming $ scp mercurial-1.0.1.tar.gz email@example.com:
sofeng@web36:~ $ mv mercurial-1.0.1.tar.gz ~/tmp
$ cd tmp
$ tar zxvf mercurial-1.0.1.tar.gz
$ cd mercurial-1.0.1
$ make install-home
$ export PYTHONPATH=$HOME/lib/python:$PYTHONPATHNote: you will need to put this in your
.bashrcinstead of your
.bash_profilebecause Mercurial only executes
.bashrcon a remote
hg pushby default.
$ hg version Mercurial Distributed SCM (version 1.0.1) Copyright (C) 2005-2008 Matt Mackall
and others This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- No module name django.core.management
$ python manage.py syncdb Traceback (most recent call last): File "manage.py", line 2, in ? from django.core.management import execute_manager ImportError: No module named django.core.managementYou need to set the
$ export PYTHONPATH=$HOME/webapps/djangoYou may get this if you use
python manage.py syncdbinstead of
python2.5 manage.py syncdb.
Django Blog Project #1: Creating a basic blog
Django Blog Project #3: Using CSS and Template Inheritance
Django Blog Project #4: Adding post metadata
Django Blog Project #5: YUI CSS and serving static media