Jump to content

Recommended Posts

Posted

Hello, sorry to bother you admins/forum members, but I'm having problem with the setup of a django application I just uploaded.

 

I followed the steps here, handled all chmod's, etc.

The only stuff I did differently is placing the .htaccess directly inside public_html instead of in the django app subfolder, and added some rewrites for static content.

my cpanel name: gcatania

site name: ceciliaegabriele.heliohost.org

 

This is my .htaccess with path /home/gcatania/public_html/.htaccess:

# -FrontPage-


AuthUserFile /home/gcatania/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/gcatania/public_html/_vti_pvt/service.grp


<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName ceciliaegabriele.heliohost.org
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(admin_media/.*)$ - [L]
RewriteRule ^(dispatch\.wsgi/.*)$ - [L]
RewriteRule ^img/(.*)$ /static/img/$1 [L]
RewriteRule ^layout/(.*)$ /static/layout/$1 [L]
RewriteRule ^js/(.*)$ /static/js/$1 [L]
RewriteRule ^(.*)$ wedsite/dispatch.wsgi/$1 [QSA,PT,L]

 

the strange thing is, when I remove that last line, at least static content is served correctly. With that last line, i get a status 500 even on urls that should serve static content (e.g. http://www.ceciliaegabriele.heliohost.org/img/wip1.png )

 

here is my dispatch.wsgi with path /home/gcatania/public_html/wedsite/dispatch.wsgi

 

import os, sys
sys.path.append("/home/gcatania/public_html/wedsite");
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
os.environ['PYTHON_EGG_CACHE'] = '/home/gcatania/.python_egg_cache'
import django.core.handlers.wsgi
_application = django.core.handlers.wsgi.WSGIHandler()
def application(environ, start_response):
   environ['PATH_INFO'] = environ['SCRIPT_NAME'] + environ['PATH_INFO']
   return _application(environ, start_response)

 

django app is in /home/gcatania/public_html/wedsite

 

I checked the cpanel error log and it only shows a couple lines about a 404.html missing.

 

I pulled an all-nighter trying to make it work, but with no success. Tried switching mysql settings with the sqlite3 I'm using for development, but the error does not come from there.

Can anyone point me in the right direction?

Thank you very much for your time...

Posted

All right, I spent a couple more time around the forums and noticed the server admin (and proably the only person that can help me) was last seen around here more than one month ago. Anyway, I'm not giving up that easy, so here's what I came up with while trying to get as close as possible to the solution:

 

1) I noticed the dispatch.wsgi only seems to work when it's placed in public_html, so I placed it there.

2) I made some adjustments and tested with the suggested debug wsgi script from the WSGI quick config guide:

def application(environ, start_response):
   status = '200 OK'
   output = 'Hello World!'

   response_headers = [('Content-type', 'text/plain'),
                       ('Content-Length', str(len(output)))]
   start_response(status, response_headers)

   return [output]

 

I also modified my .htaccess in public_html so that every non-static url maps to the wsgi script. Here it is:

# -FrontPage-


AuthUserFile /home/gcatania/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/gcatania/public_html/_vti_pvt/service.grp


<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName ceciliaegabriele.heliohost.org
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(admin_media/.*)$ - [L]
RewriteRule ^(dispatch\.wsgi/.*)$ - [L]
RewriteRule ^img/(.*)$ /static/img/$1 [L]
RewriteRule ^layout/(.*)$ /static/layout/$1 [L]
RewriteRule ^js/(.*)$ /static/js/$1 [L]
RewriteRule ^(.*)$ dispatch.wsgi/$1 [QSA,PT,L]

 

 

Now every url maps to my dispatcher.wsgi that just outputs the string "wip!!", and the "only" step left is to make Django work.

I also managed to obtain the environment contents:

{
'REDIRECT_UNIQUE_ID': 'Swb2LEETjwIAADZqs2wAAAAj',
'mod_wsgi.listener_port': '80',
'HTTP_COOKIE': '__utma=149771567.3713108818195957000.1249680808.1258682284.1258742175.10; __utmz=149771567.1258742175.10.3.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=heliohost%20environ; __utmc=149771567',
'mod_wsgi.listener_host': '0.0.0.0',
'REDIRECT_STATUS': '200',
'SERVER_SOFTWARE': 'Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8e-fips-rhel5 mod_wsgi/3.0c3 Python/2.4.3 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635',
'SCRIPT_NAME': '/dispatch.wsgi',
'mod_wsgi.handler_script': '',
'SERVER_SIGNATURE': '<address>Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8e-fips-rhel5 mod_wsgi/3.0c3 Python/2.4.3 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at ceciliaegabriele.heliohost.org Port 80</address>\n',
'REQUEST_METHOD': 'GET',
'HTTP_KEEP_ALIVE': '300',
'REDIRECT_URL': '/',
'SERVER_PROTOCOL': 'HTTP/1.1',
'QUERY_STRING': '',
'PATH': '/sbin:/usr/sbin:/bin:/usr/bin',
'HTTP_ACCEPT_CHARSET': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.0.15) Gecko/2009101601 Firefox/3.0.15 (.NET CLR 3.5.30729)',
'HTTP_CONNECTION': 'keep-alive',
'SERVER_NAME': 'ceciliaegabriele.heliohost.org',
'REMOTE_ADDR': '94.36.111.88',
'mod_wsgi.request_handler': 'wsgi-script',
'wsgi.url_scheme': 'http',
'PATH_TRANSLATED': 'redirect:/dispatch.wsgi/',
'SERVER_PORT': '80',
'wsgi.multiprocess': True, 'mod_wsgi.input_chunked': '0',
'SERVER_ADDR': '65.19.143.3',
'DOCUMENT_ROOT': '/home/gcatania/public_html',
'mod_wsgi.process_group': '',
'SCRIPT_FILENAME': '/home/gcatania/public_html/dispatch.wsgi',
'SERVER_ADMIN': 'webmaster@ceciliaegabriele.heliohost.org',
'wsgi.input': <mod_wsgi.Input object at 0x2b249d8a0fb0>, 'HTTP_HOST': 'ceciliaegabriele.heliohost.org',
'wsgi.multithread': False, 'mod_wsgi.callable_object': 'application',
'HTTP_CACHE_CONTROL': 'max-age=0',
'REQUEST_URI': '/',
'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'wsgi.version': (1, 0), 'GATEWAY_INTERFACE': 'CGI/1.1',
'wsgi.run_once': False, 'wsgi.errors': <mod_wsgi.Log object at 0x2b249bf21570>, 'REMOTE_PORT': '50527',
'HTTP_ACCEPT_LANGUAGE': 'en-us,en;q=0.5',
'mod_wsgi.version': (3, 0), 'mod_wsgi.application_group': 'ceciliaegabriele.heliohost.org|/dispatch.wsgi',
'mod_wsgi.script_reloading': '1',
'wsgi.file_wrapper': <built-in method file_wrapper of mod_wsgi.Adapter object at 0x2b249d8b1918>, 'HTTP_ACCEPT_ENCODING': 'gzip,deflate',
'UNIQUE_ID': 'Swb2LEETjwIAADZqs2wAAAAj',
'PATH_INFO': '/dispatch.wsgi/'
}

Help / hints / comments / rants appreciated.

Posted

Still messing around, now with the wsgi dispatcher:

 

I managed to get the dispatcher to output errors to the browser by doing this:

import os, sys
sys.path.append("/home/gcatania/public_html");
sys.path.append("/home/gcatania/public_html/wedsite");

os.environ['DJANGO_SETTINGS_MODULE'] = 'wedsite.settings'
os.environ['PYTHON_EGG_CACHE'] = '/home/gcatania/.python_egg_cache'
import django.core.handlers.wsgi
_application = django.core.handlers.wsgi.WSGIHandler()
def application(environ, start_response):
   environ['PATH_INFO'] = environ['SCRIPT_NAME'] + environ['PATH_INFO']
   try:
       test = _application(environ, None)
   except Exception, e:
       test = str(e)
   status = '200 OK' 
   response_headers = [('Content-type', 'text/plain'),
                       ('Content-Length', str(len(test)))]
   start_response(status, response_headers)
   return [test]

 

Here's what I got:

Can't extract file(s) to egg cache

The following error occurred while trying to extract file(s) to the Python egg
cache:

 [Errno 13] Permission denied: '/home/gcatania/.python_egg_cache/pysqlite-2.5.0-py2.4-linux-x86_64.egg-tmp'

The Python egg cache directory is currently set to:

 /home/gcatania/.python_egg_cache

Perhaps your account does not have write access to this directory?  You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.

Will work on the directory's permission now.

Posted

Hi, and thanks for the guide, I'm struggling with normal Python without django, could you help me with that? Did you try it?

With a simple script like this:

 

#!/usr/bin/python

print "Content-Type: text/plain\n\n"

print "python"

 

All I'm getting is Internal Server Error 500 :(

It is in cgi-bin and have extension .cgi, tried .py and no success either.

 

If you have no clue, then maybe I will try your django configuration and post my results.

 

 

Using your django settings and some bad configuration files I managed to get response

500.html

 

on every address I enter on my account; I need some good tutorial about manual django configuration;

 

Posted

All right, I'll post as much as I can here, step by step.

 

DISCLAIMER: this is how I succeeded, no doubt there are way better solutions around (e.g. place config files in the correct directories), but this is the simplest configuration and the only one that just worked for me so far.

 

In order to test a simple django application, try the following:

 

1. create a file named dispatch.wsgi in your public_html folder (/home/username/public_html), containing exactly the following (taken from the WSGI quick conf guide)

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

 

2. give permissions 755 to this file

3. edit (do not replace!) the file named .htaccess in your public_html folder and append the following

RewriteEngine On
RewriteBase /
RewriteRule ^(dispatch\.wsgi/.*)$ - [L]
RewriteRule ^(.*)$ dispatch.wsgi/$1 [QSA,PT,L]

4. give permissions 644 to this file

5. fire up your website, any address you type before the / should yeld "Hello World!" as response. If it doesn't, you did something wrong, or I wrote something wrong here. In which case, let me know.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...