views:

326

answers:

5

I would like to deploy my django pet-project on our student server. We have apache2 with UserDir mod and I don't have access to apache2 config files. How do I deploy? :-D

I come from PHP background and I deploy my PHP scripts by uploading them to my public_html dir and everything shows up on http://ourserver.com/~myusername. I read django documentation and it says I should add <Location>some stuff</Location> to our apache config file. I don't have access to it, so I tried putting it in .htaccess in my public_html dir and that didn't work. I googled a lot and I think I read somewhere you can't put <Location> in .htaccess, but now I can't find that quote.

So, anybody here deployed django to UserDir without harassing apache admins?

edit: I tested mod_python as Graham Dumpleton advised here, and I can use mod_python without problems. Also, I found error log and here is what error log says when I put <Location>some stuff</Location> in .htaccess:

"[Thu Oct 01 21:33:19 2009] [alert] [client 188.129.74.66] /path/to/my/.htaccess: <Location not allowed here"

So, it seems like I really can't put <Location> into .htaccess. So, what are my options?

A: 

Are mod_python or mod_wsgi enabled on the base Apache? You'll need that as a minimum.

Daniel Roseman
He said he doesn't have access to Apache configuration files so neither mod_wsgi or mod_python will be of any use. Even if administrators installed mod_python it will be of no use as it doesn't provide user separation. You can get user separation for daemon mode of mod_wsgi, but means manual configuration on a per user basis by the administrators, which they are going to be unlikely to want to do. Other option is to see whether the Apache instance has one of the FASTCGI modules installed.
Graham Dumpleton
mod_python is enabled, mod_wsgi is not.
dijxtra
mod_fastcgi is also not enabled.
dijxtra
A: 

Would you be allowed to run your own long-running server process on some port other than 80? This might allow you to serve Django content either with a Django test server or your own copy of Apache with local configuration files.

That might be possible. Django test server is out of the question for production, but my own copy of Apache with alternative port number could be a solution if there is no other. Now, this is something I could approach my admin with. Thanks.
dijxtra
A: 

If mod_python installed, first see if you can actually use it without needing administrator to do anything. Read:

http://www.dscpl.com.au/wiki/ModPython/Articles/GettingModPythonWorking

Unless you are a trusted user or administrators don't know what they are doing, they shouldn't be allowing you to use mod_python because your code will run as Apache user and if anyone else also running applications same way, you could interfere with each others applications and data. In other words it isn't secure and shouldn't be used in shared hosting environments where multiple users on same Apache instance.


UPDATE 1

On the basis that you now have mod_python working, you should be able to replace contents of mptest.py with something like:

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import sys
sys.path.insert(0, '/some/path/to/project/area/mysite')
sys.path.insert(0, '/some/path/to/project/area')

from django.core.handlers.modpython import handler as _handler

def handler(req):
  req.get_options()['django.root'] = '/~myusername/mptest.py'
  return _handler(req)

Obviously, various paths and values in that should be changed per your naming.

The site would be accessed as '/~myusername/mptest.py'.

At this point you will find out silly using mod_python is where you don't have control of Apache. This is because when you change code in your site, you will need to ask the administrators to restart Apache for you for your changes to be picked up.

Using mod_wsgi in its daemon mode with you as owner of daemon process would be much better, but if they are already running mod_python I wouldn't be recommending they load both modules at same time as mod_python issues screw up use of mod_wsgi in some cases and if they haven't installed Python properly, you are just likely to have lots of issues and so not worth the trouble.

In short, using mod_python in shared hosting environment where you have no control of Apache is silly and insecure.

All the same, have documented how to run Django out of per user directory as I don't think it has been documented anywhere previously.

Graham Dumpleton
Sorry for the delay, I'm busy as hell, I'll test my mod_python tomorrow afternoon (GMT). The article seems great, I figured out we have mod_python 3.3.1 on our server but I didn't get any further since I mush go now. I'll get back here tomorrow, I would really like to solve this thing...
dijxtra
Damn. I couldn't run mptext.py from that article, I get 403 forbidden. I sent an email to my admin and asked him to allow me to use mod_python. I'll get back to you when he responds and I get a working mod_python environment.
dijxtra
Finally. I couldn't finish the test from the link you provided because my .htaccess was 700. I fixed that and now I can see "mptest.py". Therefore, I can use mod_python without problems. BTW, my admin told me where error log is so I added additional info to my original question. I probably should have checked that first.
dijxtra
A: 

Have you tried using <Directory> instead of <Location>? If that isn't blocked by local policy you should be able to do something like this:

<Directory /path/to/your/home/public_html>
# mod_python stuff here
</Directory>

I'd go with either mod_wsgi or fastcgi if you're on good terms with your admin. If that's the case, however, you should simply be able to give your admin the mod_wsgi config since it supports update-based reloading and running as an alternate user. He should be able to set it up to simply run a single wsgi file under your account - something like this, possibly with an allow from all depending on how security is configured:

<Directory /home/you/public_html>
WSGIApplicationGroup PROJECT
WSGIDaemonProcess YOU threads=15 processes=2 python-path=/home/YOU/.virtualenvs/PROJECT-env/lib/python2.6/site-packages
WSGIProcessGroup YOUR_GROUP
WSGIScriptAlias / /home/YOU/PROJECT/deploy/PROJECT.wsgi
</Directory>

As an aside, the above assumes the use of the awesome, highly-recommended virtualenv and virtualenvwrapper to create a local python sandbox in your home directory. This will massively simplify life running as a non-admin or when you have more than one project. If you don't use virtualenv the python-path above can be removed entirely.

Chris Adams
Neither Location or Directory directives can be used in .htaccess files.
Graham Dumpleton
A: 

If mod_fcgi is configured, you can use that. See http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/

Gary van der Merwe