ThomasAFink
ThomasAFink

Reputation: 1387

Hosting Django with passenger_wsgi.py

I'm having trouble setting up my django on dreamhost shared hosting using python passenger_wsgi.py and virtual env. When I run passenger_wsgi.py no error is returned and the shell prints my project path. My website shows a 500 International server error. I have cleared my cache so there is no cache error. How do I set this up properly?

django 1.9 python 2.7 apache

My site structure is:

/home/myuser/mydomain.com/
   env/
   myApp/
   passenger_wsgi.py
   public/

passenger_wsgi.py

import sys, os
cwd = os.getcwd()
sys.path.append(cwd)

project_location = cwd + '/myApp'
print (project_location)
sys.path.insert(0, project_location)

#Switch to new python
if sys.version < "2.7.3": os.execl("/home/myuser/mydomain.com/env/bin/python",
"python2.7.3", *sys.argv)

sys.path.insert(0,'/home/myuser/mydomain.com/env/bin')
sys.path.insert(0,'/home/myuser/mydomain.com/env/lib/python2.7/site-packages/django')
sys.path.insert(0,'/home/myuser/mydomain.com/env/lib/python2.7/site-packages')


os.environ['DJANGO_SETTINGS_MODULE'] = "myApp.settings"

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Upvotes: 0

Views: 6092

Answers (1)

Tristan
Tristan

Reputation: 141

I had issues with Dreamhost specifically when upgrading from Django 1.6 to 1.8. One of the issues was with the WSGIHandler(). I can't say this is your problem specifically, but you can try setting application like this:

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Finally - make sure you restart passenger. There are docs here about how to do it: http://wiki.dreamhost.com/Passenger

From that page:

Whenever the code or configuration files for your application are modified, you must create or update the modification date of the file "tmp/restart.txt" in the application's root directory tree in order to trigger Passenger to reinitialize the application. Passenger caches many resources so changes are not recognized unless the modification date of "tmp/restart.txt" is changed.

The most common method to make this change is to run "touch tmp/restart.txt" via SSH. (Ruby on Rails automatically creates a directory named "tmp". If you are creating non-RoR application, you may need to create the "tmp" directory manually.

Upvotes: 1

Related Questions