By PM Hansen
VP Clear Cloud Network
I host Zoning at Pisso on an Ubuntu cloud server. If you don't mind doing a little server maintenance, it is, in my opinion, the best way
to host your Django project. (And if you do mind server maintenance, check out Web Faction.)
I just managed to successfully
upgrade an Ubuntu Intrepid server configured for Django to Ubuntu Feisty. Since you're here, you're probably trying to do
something similar, so I hope these instructions help. My initial build more or less followed these instructions. You may want to check and see how closely your build matches mine before proceeding.
Your first task is upgrading the server. (All performed as root.)
- sed -e 's/\intrepid/ jaunty/g'
-i /etc/apt/sources.list
- apt-get
update
- apt-get dist-upgrade
The next part was tougher to figure out. It turns out
that Ubuntu Jaunty ships with Python 2.6 as the default Python version. Python 2.6 has changed the site-packages directory
(/usr/lib/python2.5/site-packages) to dist-packages (/usr/lib/python2.6/dist-packages). It's a sensible name change, so I'm
not complaining.
I had a lot
of stuff in site-packages – including my Django core files – so rather than symlink everything therein, I just
deleted the bits already in the dist-packages directory and moved the contents of site-packages over. So:
- sudo mv /usr/lib/python2.5/site-packages/* /usr/lib/python2.6/dist-packages
You've probably also symlinked
the admin media from your Django install into your project, so be sure to delete and recreate that link. For me, that process
looked like this:
- sudo
rm /home/dawsoning/public_html/static.dawsoning.com/admin
- sudo ln -s /usr/lib/python2.6/dist-packages/django/contrib/admin/media /home/dawsoning/public_html/static.dawsoning.com/admin
Happy upgrade cloud dudes...and
gals....!
By Peter Hansen
VP Clear Cloud Networks with Clear Wire
Today I had the task of installing a development server running the Django Python framework
for one of our web developers.
I learned a few things and I figured a quick tutorial might
help someone else out. None of this covers new ground, but perhaps another telling of the story will help someone out there.
I started from scratch, with a basic install of Ubuntu 7.04 Server Edition. I did not choose any extra packages, such as the
LAMP option or DNS server. If you are starting off with a LAMP server already installed, or a different version, the steps
will be similiar, but you may need to adapt some commands to
get them to work.
Install server software
Install Apache, Mod_Python, MySQL and MySQLdb. MySQLdb is the database bindings
for MySQL. Django also supports PostgreSQL, Oracle and SQLite. If you choose
to use a different database server, be sure to install the appropriate
Python bindings.
sudo apt-get install apache2 libapache2-mod-python sudo
apt-get install
mysql-server python-mysqldbInstall the Django source code
At this point you have a couple of options. You could “apt-get install” a Django package, install an
official release or install the development version. I chose to
install the development version because it contains the latest bug fixes and features.
We’ll be checking out the latest version from
its Subversion repository. You’ll want to be in your home directory when you do this.
cd ~/ svn co http://code.djangoproject.com/svn/django/trunk/ django_src
Python won’t recognize Django
unless it is installed in the “site-packages” directory, so instead we just create a
symbolic link to the source code in our home directory. Run the first command to
find out the path to your “site-packages” directory.
Then use it in the second command, in place of “YOUR-DIR”. Lastly, copy the django-admin.py
file into /usr/local/bin so that we don’t have to qualify the
command with the full path to the file.
python -c "from
distutils.sysconfig import get_python_lib; print get_python_lib()" ln -s `pwd`/django_src/django YOUR-DIR/django sudo
cp ~/django_src/django/bin/django-admin.py /usr/local/binCreate Django’s directories
Next we need to create some directories
that Django will use. Once again, create these under your home directory.
cd ~/
mkdir django_projects mkdir django_templates mkdir mediaThen we need to create some symbolic
links in your webroot. The default webroot for an Apache2
installation on Ubuntu is /var/www. We are going to create a link to the media folder in your home directory,
and a link to the admin_media folder which is
provided in the Django source code.
cd /var/www sudo ln -s ~/media
media sudo ln
-s ~/django_src/django/contrib/admin/media admin_mediaCreate a Django project
Move into your Django projects directory
that we just created. We will be starting a
new project using Django’s command line utility. This will give us a basic directory
structure and the necessary configuration files. In
my example I named the project “myproject.”
Feel free to choose any name, as long as it does not conflict with any built-in Python or Django components.
In particular, this means you should avoid using names
like django (which will conflict with Django itself)
or site (which conflicts with a built-in Python package).
cd
~/django_projects django-admin.py startproject myprojectEdit the myproject/settings.py file
and change the following sections:
Uncomment and change the ADMINS setting
6
7 8 9 10 | ADMINS = ( ('Your Name', 'your_email@domain.com'), ) |
Enter your database settings. You
will need your database, username and password.
Most likely your database server is running on the same server,
so leave DATABASE_HOST blank.
Change your timezone if necesary.
Point Django at the template directory we created.
69 70 71 72 73 74 75 | TEMPLATE_DIRS
= ( "/home/YOUR_USERNAME/django_templates"
# Put strings
here, like "/home/html/django_templates" or "C:/www/django/templates".
) |
Do the same thing for the media url and directory we
created earlier.
Set the admin media directory that we created in your webroot
45 46 47 48 49 50 51 | # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a # trailing slash. # Examples: "http://foo.com/media/", "/media/". ADMIN_MEDIA_PREFIX = '/admin_media/' |
And finally, add the admin application
to your install applications
76 77 78 79 80 81 82
83 84 85 86 87 88 | INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin', ) |
After making all those changes to
the configuration we need to synchronize the Django database.
Youll also get a prompt asking you if you�d like to create a superuser account for the authentication system.
Go ahead and do that.
Then
your install is semi completed....see clear cloud link on hm pg....