Reputation: 2751
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?
Upvotes: 0
Views: 1764
Reputation: 9543
If mod_fcgi is configured, you can use that. See http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/
Upvotes: 0
Reputation: 58563
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.
Upvotes: 1
Reputation: 5021
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.
Upvotes: 0
Reputation: 37103
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.
Upvotes: 0
Reputation: 599788
Are mod_python
or mod_wsgi
enabled on the base Apache? You'll need that as a minimum.
Upvotes: 0