Deploy Django on shared web hosting like Bluehost
- 21 Dec 2008
- Posted in django
Last weekend, I took some time to setup Python and Django on our hosting server which is bought from Bluehost. I also bound a domain name to my working space afterwards. Here is a walk-though for all work need to do.
REXML could not parse this XML/HTML:
<ol>
<li><strong>Install Python
</strong>There is an old version of shared Python on the server, but even it’s not too old to be used, I’d rather to install my own one. Because I will use some Python libraries and applications, and I can only install them by my permission level. It’s quite easy if you already have SSH access. One one thing may need to be concerned, that is to configure installation path. Such as, "./<strong>configure -prefix=/home/USERNAME/python -enable-unicode=ucs4</strong>".
Here is <a href="http://www.2maomao.com/blog/your-own-python-on-bluehost/" target="_blank">a full list</a> how to do that from a Chinese blog.</li>
<li><strong>Install flup/mysql-python
</strong>Before you install these components, I’d like to suggest you install <a href="http://peak.telecommunity.com/DevCenter/EasyInstall" target="_blank">EasyInstall</a> at first. Then you can run it to install others:
<strong>easy_install mysql-python
easy_install flup</strong>
Maybe you need to install other libraries here, just go ahead.</li>
<li><strong>Install Django
</strong>I didn’t find SVN was working on server. And I chose a release version of Django(1.0). So pick up a folder and run wget command, and install it with classic 3 commands.</li>
<li><strong>.htaccess and fastcgi settings
</strong>New a web folder under <strong>public_html </strong>folder(which will be published), and create both files under it:
<pre># .htaccess file
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(static/.*)$ - [L]
RewriteCond %{REQUEST_URI} !(dispatch.fcgi)
RewriteRule ^(.*)$ dispatch.fcgi/$1 [L]
dispatch.fcgi file
!/home/USERNAME/python/bin/python
import sys, os
Add a custom Python path.
sys.path.insert(0, “/home/USERNAME/python”) sys.path.insert(0, “/home/USERNAME/Django-1.0”) os.chdir(“/home/USERNAME/Django-1.0/PROJECTNAME”) os.environ‘DJANGO_SETTINGS_MODULE’ = “PROJECTNAME.settings” from django.core.servers.fastcgi import runfastcgi runfastcgi(“method=threaded”, “daemonize=false”)</pre> </li>
REXML could not parse this XML/HTML: <li><span>You need to set proper rights(chmod +x) for dispatch.fcgi file. In dispatch.fcgi file, you need to replace USERNAME and PROJECTNAME with your own names. "Django-1.0" is my folder where my Django installed.
REXML could not parse this XML/HTML: </span>
Besides, you probably want to confirm FastCGI is installed from your hosting settings, I tried that also but I didn’t find it. So far as I know, FastCGI has been enabled by default on Bluehost. And the file name “dispath.fcgi” is from somewhere, somebody’s experience that corn jobs on server will search and kill suspended processes without these names.</li>
REXML could not parse this XML/HTML: <li><span><strong>Start project</strong></span><span>It should be ready so far. Go to your Django folder,and rock your project with the name specified before:</span>django-admin.py startproject PROJECTNAME
<li><strong>Setup domain name</strong>It’s quite easy to add a new domain in cPanel. Just add a new addon domain and match the domain folder with the one where you place .htaccess and dispatch.fcgi files. Copy the A record IP address and save it to your IP settings. Restart VDNS if you have that. You can also use the subdomain you just created from cPanel. That’s all!</li>
<li>When you domain name is active you should be able to see something familiar</li>
REXML could not parse this XML/HTML: </ol>
If you meet problems do check thing below:
- Don’t confuse yourself by different path of your Python, Django, Project and publish folder.
- You need to have permissions run dispatch.fcgi file.(chmod +x dispatch.fcgi)
- If you see Unhandled Exception errors, please be sure that you place your project under Django installed folder.(I haven’t figured why should be like this.)
- If you still have problems, don’t hesitate to leave your comments here.