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 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/" to the httpd.conf file.
3. Add "WSGIScriptAlias /django "D:\...\webprojects\tutorial\tutorial\"" to the configuration file. This basically says, for any request with path "django", please use 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">
  Order deny,allow
  Allow from all
This allows the access to all 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 ; 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.

No comments: