Saturday, May 25, 2013

Apache 2.4, Django 1.5, Python 3.3 configuration on Windows

It's not so easy to get Django 1.5 configured with Apache 2.4 on windows.
Most information/documentation related to such configuration is on Linux and on earlier versions of apache or django. Some of them might be misleading for the configuration on windows. For example, some say privilege needs to be changed, others say wsgi.py file needs to be changed.
Here I'd like to explain what I've done to make it work on windows.
1. Get mod_wsgi of the correct version for apache and python. (Believe me it's not so easy to compile it by yourself on windows.) Where to get it is described in my previous post.
2. Configure the module loading in apache http server by first adding the module to apache module directory and then add "LoadModule wsgi_module modules/mod_wsgi.so" to the httpd.conf file.
3. Add "WSGIScriptAlias /django "D:\...\webprojects\tutorial\tutorial\wsgi.py"" to the configuration file. This basically says, for any request with path "django", please use wsgi.py to handle it.
4. Add "WSGIPythonPath "D:\...\webprojects\tutorial"" to the conf file. This points out where python modules can be found. You can add multiple paths (separated by ";") to it.
5. Add the following directory directive:
<Directory "D:\...\webprojects\tutorial">
<Files wsgi.py>
  Order deny,allow
  Allow from all
</Files>
</Directory>
This allows the access to all wsgi.py files in the directory and its subdirectories.
6. Description of all the above steps can be found with a bit googling. However, after all these steps are done properly, you would still get http 403 access denied error. (In the error log, you'll see "AH01630: client denied by server configuration:").
It seems the "Allow"  directive not working at all.
By checking http://httpd.apache.org/docs/2.4/mod/mod_access_compat.html#allow ; it can be seen "The directives provided by mod_access_compat have been deprecated by the new authz refactoring. Please see mod_authz_host." By following the link, you'll find that "Require" directive should be used instead.
So what still needs to be done is to replace "Allow from all" with "Require all granted".
After these 6 steps, you django 1.5 app can be running on apache 2.4 on windows.

Thursday, May 09, 2013

Configure Apache 2.4 with Django (Python3.3) on windows

Installing/configuring Apache2.4 with Django on Linux is easy, while doing the same thing on windows can be tricky due to incompatible vc libs, win sdk libs, python libs and so on. I've tried to compile the mod_wsgi several times, but faced some strange errors (I'm sure make file is updated properly). I found a good site where you can get compiled wsgi module: http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi .