Reputation: 3325
I downloaded mod_wsgi from the following location for apache 2.2 and python 2.7 (64bit). (I'm trying to get django to run on my computer).
Whenever I add the following line:
LoadModule wsgi_module modules/mod_wsgi.so
Apache fails to start up. Can anyone tell me what the issue might be?
Upvotes: 13
Views: 29261
Reputation: 441
How I configured Apache + Django + venv
For it to work you need 3 things:
mod_wsgi
on python and apachehttpd.conf
on apachemod_wsgi
and in turn loads your python app1. Is described well enough in the official doc (I used the pip method). Just unpack apache distro (ApacheHaus worked for me, but not Apache Lounge, it missed some headers I think) to a standard place like C:\
or set env var MOD_WSGI_APACHE_ROOTDIR
to its dir. You'll need Visual Studio Build Tools or binary distribution of mod_wsgi. Then pip install
it.
2. In httpd.conf add:
LoadFile ".../pythonXY/pythonXY.dll"
LoadModule wsgi_module ".../mod_wsgi/server/mod_wsgi.cpXY-win_amd64.pyd"
WSGIPythonHome ".../pythonXY"
WSGIScriptAlias / "...\wsgi.py"
Here LoadFile
may be necessary if Python isn't installed the standard way. Better to include.
WSGIPythonHome
directive should point to main python distro (not venv as is usually said), because mod_wsgi may be somewhat not working properly. For instance now WSGIPythonPath
is doing nothing at all. Alternatively, you can set PYTHONPATH or PYTHONHOME env vars accordingly.
Now you can monitor error log of apache (inside its log folder by default). In case of failures apache will print mod_wsgi configuration (meaning it is installed, but couldn't start python) and/or python errors if it managed to start.
3. Inside your python script (wsgy.py
) you'll need to provide function "application" (so is mod_wsgi
usually compiled) which starts your app. But first point python to the modules and packages it will use, your own as well, right in the script with sys.path
or site.addsitedir
. Django's wsgi.py is good, just prepend all path conf there.
Upvotes: 0
Reputation: 3227
Apart from Olly's correction, there is another error in Step6: Instead of
Include "d:/projects/mysite/apache_django_wsgi.conf"
it should be
Include "d:/projects/mysite/apache/apache_django_wsgi.conf"
I made all the steps and now can't start Apache Server anymore. The Wamp Image is red. I could restart Apache as described in Step 3.
Upvotes: 0
Reputation: 851
Only for users running windows 64 versions.
I have created wsgi. Now you only need to install python and run apache. The configurations have already been set in the package. Just download the package and follow the instructions from 'Steps to follow.txt file' present in package.
You dont need to download python and apache and mod_wsgi.so from anywhere. I have compiled the so file, and compatible python and apache2 versions. So that you are ready to deploy. Just that in apache config the document root has been set to cgi-bin folder present inside Apache2.
Package can be downloaded from Zip package
Instructions and package usage
Upvotes: -1
Reputation: 1
Just in case anyone is using this and doesn't spot it, there is an inconsistency in the steps. In Step 5 it refers to the filename apache_mydjango.conf
In Step 6 it refers to the filename apache_django_wsgi.conf
These should obviously both be the same name - it doesn't matter which way round you go for - but I spent a while trying to figure out why it wasn't working.
Upvotes: 0
Reputation: 1
Try the following websites for the unofficial windows binaries for python extensions http://www.kaij.org/blog/?p=123 https://github.com/kirang89/pycrumbs/pull/28
Upvotes: 0
Reputation: 4753
These are the following things you need to do to setup Apache for Django. I assume you are using Python 2.7 (32-bit) on Windows (32-bit) with WAMP server (32-bits) installed.
Download mod_wsgi-win32-ap22py27-3.3.so. Or download your respective .so compatible file
Change its name to mod_wsgi.so
and copy it to /Program Files/Apache Software Foundation/Apache22/modules
on Windows.
Open httpd.conf
using Admin rights. Now, you will find a list of lines with LoadModule ...
. Just add LoadModule wsgi_module modules/mod_wsgi.so
to that list.
Your are partially done.. you can restart the apache and shouldn't find any errors.
Now you need to link it to your Django project.
In your Django project root folder, add apache
folder and create django.wsgi
(don't change this name) and apache_mydjango.conf
.
In httpd.conf
add the following line at the bottom of the page.
Include "d:/projects/mysite/apache_django_wsgi.conf"
Open django.wsgi
and add the following lines:
import os, sys
sys.path.append('d:/projects/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Open apache_djang_wsgi.conf
and add:
Alias /images/ "d:/projects/mysite/templates/images/"
<Directory "d:/projects/mysite/images>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / "d:/projects/mysite/apache/django.wsgi"
<Directory "d:/projects/mysite/apache">
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot d:/projects/mysite
ServerName 127.0.0.1
</VirtualHost>
Note:
I am assuming your Django project hierarchy is something like this:
mysite/
mysite/
settings.py
urls.py, wsgi.py.
manage.py
<apache> / apache_django_wsgi.conf, django.wsgi
Best tutorial links:
Actually I don't understand why people are unable to fix it. I've seen lots of questions on it here and I even posted few...So, I thought to write a initial setup version directly as answer
Upvotes: 27