Django Blog Project #2: Django Webfaction deployment
This is my OLD blog. I've copied this post over to my NEW blog at:
http://www.saltycrane.com/blog/2008/06/first-django-webfaction-deployment/
You should be redirected in 2 seconds.
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 sofeng@sofeng.webfactional.com: $ scp .screenrc sofeng@sofeng.webfactional.com: $ scp .emacs sofeng@sofeng.webfactional.com:
Reinstall Django
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:": django
Then 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
http://sofeng.webfactional.com
.
Upload my project
- The welcome message recommends using
sftp
, but I usedrsync
instead because I'm more familiar with it:sofeng@home:~ $ rsync -avz ~/src/django/myblogsite sofeng@sofeng.webfactional.com:webapps/django
Deploy
- I ssh'd into my webfaction shell account:
sofeng@home:~ $ ssh sofeng@sofeng.webfactional.com
- 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.py
file. 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 syncdb
again:$ 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
httpd.conf
:SetEnv DJANGO_SETTINGS_MODULE myblogsite.settings
- Then I restarted the Apache server:
$ ~/webapps/django/apache2/bin/restart
- 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://saltycrane.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
httpd.conf
: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/myview1
and saw my page. Success! - Note, If you want to see the live site, the real location is: http://saltycrane.com/myview1. It's not very exciting now, but hopefully I will be able to add some CSS and more blog metadata soon.
Install Mercurial
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 ~/bin
and ~/lib
.
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 sofeng@sofeng.webfactional.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:$PYTHONPATH
Note: you will need to put this in your.bashrc
instead of your.bash_profile
because Mercurial only executes.bashrc
on a remotehg push
by 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.
Other Errors
- 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.management
You need to set thePYTHONPATH
:$ export PYTHONPATH=$HOME/webapps/django
You may get this if you usepython manage.py syncdb
instead ofpython2.5 manage.py syncdb
.
Related posts:
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
No comments:
Post a Comment