Question

I have a little issue here. I'm building a project in django on dreamhost (shared hosting). Everything is ok when i'm in debug mode and when i use the built-in server, but when i'm trying to switch to prod i get a 500 internal server error. I searched for the solution in every dark room on the internet but still didn't find it.

So, here is my setup :

my folders :

/home/user/.virtualenvs/myenv/
/home/user/project/
/home/user/project/sqlite.db
/home/user/project/project/settings.py
/home/user/example.com/project (a symlink to /home/user/project)
/home/user/example.com/passenger_wsgi.py
/home/user/example.com/public/

my passenger_wsgi.py :

import sys, os

INTERP = "/home/user/.virtualenvs/myenv/bin/python"
if sys.executable != INTERP:
    os.execl(INTERP, INTERP, *sys.argv)

sys.path.append('/home/user/.virtualenvs/myenv/lib/python3.3/site-packages')
sys.path.append('/home/user/example.com')
sys.path.append('/home/user/example.com/project')

os.environ['DJANGO_SETTINGS_MODULE'] = "project.settings"
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Does anyone knows how to solve this ?

EDIT

I forgot to mention, i installed python 3 and django 1.5 cuz the default versions in DH are too old.

Was it helpful?

Solution

In the directory /home/user/example.com you need to add a symlink to your database file too.

Also:

  • You only need to append /home/user/example.com/project to the path. The other two are not necessary, though they should not cause problems.
  • Instead of hardcoding the path /home/user/example.com/project you can use os.getcwd():

    sys.path.append(os.path.join(os.getcwd(), 'project'))
    

After you make changes to this file or other files in your project, don't forget to do touch tmp/restart.txt to notify Passenger.

By the way, at the moment Django works with Python versions 2.6.5 to 2.7 with experimental support for 3.2 and 3.3. According to the Python wiki on DreamHost, most servers should be using Python 2.6.6 as of February 2012, except some servers. Check your version of Python with python --version and if it's not 2.6.6 then you can ask the support team to upgrade it on your server.

I tried using Django with Python 3.2 or 3.3 on DreamHost but it's problematic. It doesn't work with 3.2 because the mod_wsgi module of Apache does not seem to work with this version at the moment. It could work if you install it from source, but being a shared hosting, we don't have control over that. I don't know for sure but if mod_wsgi doesn't work with 3.2 then it won't work with 3.3 either. So I think it's best to stick to a supported version of 2.x version if you want to use Django on Dreamhost.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top