絢瀬絵里
絢瀬絵里

Reputation: 1023

Setting up Django website on a shared hosting

How do you setup a Django website in a shared hosting? I've checked the django installation and it is ok

>>> import django
>>> django.VERSION
>>> (1, 4, 0, 'final', 0)

I've followed http://www.djangobook.com/en/2.0/chapter12/ section Running Django on a Shared-Hosting Provider with Apache to no avail. Currently the website is like this

/home/django_projects/WebsiteName
/sites/WebsiteName.co.id/www/.htaccess
/sites/WebsiteName.co.id/www/dispatch.fcgi

The .htaccess file is like this

AddHandler fastcgi-script .fcgi

RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ $1 [QSA,L]
RewriteRule ^(admin_media/.*)$ $1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi/$1 [QSA,L]

and the dispatch.fcgi is like this

#!/usr/bin/python
import sys, os
sys.path = ['$HOME/lib/python/Django-1.4'] + sys.path
sys.path = ['$HOME/django_projects'] + sys.path

os.chdir("$HOME/django_projects")
#from flup.server.fcgi import WSGIServer
from django.core.servers.fastcgi import runfastcgi

os.environ['DJANGO_SETTINGS_MODULE'] = 'WebsiteName.settings'
runfastcgi(["method=threaded", "daemonize=false"])

It keeps generating error 500, Internal Error when I access the website. What I tried so far are,

[1] Changing AddHandler fastcgi-script .fcgi to AddHandler fcgid-script .fcgi
[2] Removing AddHandler fastcgi-script .fcgi
[3] Putting the website directory to /sites/WebsiteName.co.id/www/WebsiteName instead of /home/django_projects/WebsiteName/
[4] Do no. 3 and move dispatch.fcgi to /sites/WebsiteName.co.id/www/WebsiteName

I'm sorry if this question is so foolish. I'm new to Django. Btw, no 1-4 is not in order. It's just to number what things I've tried so far. Also if I do no. 4, the website shows the content of dispatch.fcgi.

Upvotes: 4

Views: 8862

Answers (3)

Umer
Umer

Reputation: 580

Most of the shared hosting platforms that support python use phusion passenger to run python apps. You can upload your django app to your hosting and use wsgi to run it. As for now, django 2.2 causes problems so you will have to use django 2.1 or lower. I have written a step by step tutorial about it which can be accessed here.

Upvotes: 0

Andrew Barrett
Andrew Barrett

Reputation: 19911

Response from GoDaddy from this thread:

"FastCGI is accessible from Python scripts for our Linux hosting accounts. We do not allow, however, the addition of a custom FastCGI handler in our shared hosting accounts."

So I think you're pretty much out of luck. As am I, although I'm trying to convince the customer that having a webfaction account is a good idea, as that supports mod_wsgi.

Upvotes: 0

shakaran
shakaran

Reputation: 11122

It is more easy deploying with mod_wsgi on shared hosting. I work on Quijost and we offer a built-in package with Django 1.4 and Python 2.7 under mod_wsgi using nginx as backend. We wrote a small tutorial in our forums for mod_wsgi and maybe it is useful for your example with fastcgi.

Upvotes: 1

Related Questions