Installing mod_wsgi on WAMP server running on Windows 7

前端 未结 6 730
孤街浪徒
孤街浪徒 2020-12-02 12:34

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 follow

6条回答
  •  无人及你
    2020-12-02 13:20

    How I configured Apache + Django + venv

    For it to work you need 3 things:

    1. install mod_wsgi on python and apache
    2. setup httpd.conf on apache
    3. configure python script (usually wsgi.py) that is loaded by mod_wsgi and in turn loads your python app

    1. 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.

提交回复
热议问题