hati
hati

Reputation: 35

using Django with Apache, mod-wsgi and mod-wsgi_httpd

(Sorry, my English may be not fluent.)
I'm studying about Django, a module of Python, with Windows10, and have something to ask.
I've learned tutorial of official website of Django. Now I want to try using it with apache and mod-wsgi, but a command pip install mod-wsgi_httpd wasn't accepted. Here is what I've done or checked.
1. python3.6 works with no problem.
2. installed apache, and successed indicating default page on port 80 on localhost.
3. the command pip install mod_wsgi wasn't accepted, so I installed 'whl' file from https://www.ifd.uci.edu/~gohlke/pythonlibs/#mod_wsgi but I've not checked whether it works well because I've not installed mod-wsgi_httpd. The pip install mod_wsgi generated this error, which I couldn't deal with.(I extracted the latter part, because the log was too long.)

 copying docs\_build\html\security-issues.html -> build\lib.win-amd64-3.6\mod_wsgi\docs
    copying docs\_build\html\source-code.html -> build\lib.win-amd64-3.6\mod_wsgi\docs
    copying docs\_build\html\troubleshooting.html -> build\lib.win-amd64-3.6\mod_wsgi\docs
    copying docs\_build\html\user-guides.html -> build\lib.win-amd64-3.6\mod_wsgi\docs
    copying images\snake-whiskey.jpg -> build\lib.win-amd64-3.6\mod_wsgi\images
    running build_ext
    building 'mod_wsgi.server.mod_wsgi' extension
    Exception in thread Thread-1:
    Traceback (most recent call last):
      File "c:\python\python36\lib\threading.py", line 916, in _bootstrap_inner
        self.run()
      File "c:\python\python36\lib\threading.py", line 864, in run
        self._target(*self._args, **self._kwargs)
      File "c:\python\python36\lib\distutils\_msvccompiler.py", line 69, in _getall
        all_packages.extend(_distutils_findvs.findall())
    OSError: Error 80070002

    creating build\temp.win-amd64-3.6
    creating build\temp.win-amd64-3.6\Release
    creating build\temp.win-amd64-3.6\Release\src
    creating build\temp.win-amd64-3.6\Release\src\server
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD "-IC:/Program Files/Apache/Apache24/include" -Ic:\python\python36\include -Ic:\python\python36\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\winrt" /Tcsrc/server\mod_wsgi.c /Fobuild\temp.win-amd64-3.6\Release\src/server\mod_wsgi.obj
    mod_wsgi.c
    c:\python\python36\include\pyconfig.h(307): warning C4005: 'PLATFORM': macro redefinition
    c:\program files\apache\apache24\include\os.h(42): note: see previous definition of 'PLATFORM'
    src/server\mod_wsgi.c(471): warning C4267: 'initializing': conversion from 'size_t' to 'long', possible loss of data
    src/server\mod_wsgi.c(472): warning C4267: 'initializing': conversion from 'size_t' to 'long', possible loss of data
    src/server\mod_wsgi.c(580): warning C4267: '=': conversion from 'size_t' to 'long', possible loss of data
    src/server\mod_wsgi.c(729): warning C4267: '=': conversion from 'size_t' to 'long', possible loss of data
    src/server\mod_wsgi.c(775): warning C4267: '=': conversion from 'size_t' to 'long', possible loss of data
    src/server\mod_wsgi.c(1860): warning C4244: '=': conversion from 'Py_ssize_t' to 'long', possible loss of data
    src/server\mod_wsgi.c(3434): warning C4244: '=': conversion from 'Py_ssize_t' to 'long', possible loss of data
    src/server\mod_wsgi.c(4251): error C2065: 'wsgi_daemon_process': undeclared identifier
    src/server\mod_wsgi.c(4417): error C2065: 'wsgi_daemon_process': undeclared identifier
    src/server\mod_wsgi.c(4417): error C2223: left of '->group' must point to struct/union
    src/server\mod_wsgi.c(6052): warning C4244: 'return': conversion from '__int64' to 'long', possible loss of data
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

    ----------------------------------------
Command "c:\python\python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\拓海\\AppData\\Local\\Temp\\pip-build-brq4sh13\\mod-wsgi\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\拓海\AppData\Local\Temp\pip-zwr3dv_t-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\拓海\AppData\Local\Temp\pip-build-brq4sh13\mod-wsgi\



I'll the response of command prompt in the end of this question.

These are what I want to ask.
1. What should I do to install mod-wsgi_httpd?
2. What can I do with mod-wsgi_httpd? (the official website of Django tells me about mod-wsgi, but doesn't about mod-wsgi_httpd. The official website of Python tells me too, but it was too abstract for me.)
3. Some websites tell me that apache doesn't work without APR, but apache enabled me the default page without installing APR. Is this information wrong?

C:\Users\拓海>pip install mod-wsgi_httpd
Collecting mod-wsgi_httpd
  Using cached mod_wsgi-httpd-2.4.27.1.tar.gz
    Complete output from command python setup.py egg_info:
    'rm' は、内部コマンドまたは外部コマンド、
    操作可能なプログラムまたはバッチ ファイルとして認識されていません。
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\拓海\AppData\Local\Temp\pip-build-zt76ing5\mod-wsgi-httpd\setup.py", line 77, in <module>
        raise RuntimeError('Failed to build APR.')
    RuntimeError: Failed to build APR.

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\拓海\AppData\Local\Temp\pip-build-zt76ing5\mod-wsgi-httpd\

C:\Users\拓海>python --version
Python 3.6.4

C:\Users\拓海>pip freeze
Django==2.0.2
mod-wsgi==4.5.24+ap24vc14
mysql-connector-python==8.0.6
PyMySQL==0.8.0
pytz==2018.3

C:\Program Files\Apache\Apache24>bin\httpd.exe -v
Server version: Apache/2.4.29 (Win64)
Apache Lounge VC15 Server built:   Nov  3 2017 11:12:00

Upvotes: 1

Views: 2268

Answers (1)

charjabug
charjabug

Reputation: 38

Making sure WSGI is enabled is the first step here.

First make sure that you are loading the WSGI module in Apache. Find out where the other LoadModule lines are located and load it there. It should be in your Apache directory in conf\httpd.conf. Restart Apache and make sure the WSGI module is loaded by running httpd -t -D DUMP_MODULES or apachectl -M.

Before getting Django connected, it's a good idea to make sure a test script loads. Check out the WSGI Quick Configuration Guide. You'll see some snippets.

  • The first snippet is a WSGI script that you should put somewhere that Apache can access (but not inside a Django directory).
  • Second and third scripts go inside your VirtualHost directive in your apache2 configuration files. See the fourth script for an example of a VirtualHost using WSGI. (You might want to set up another VirtualHost on a different port [not 80 or 8000] for this WSGI test script.)

After creating the script and configuring the apache2 VirtualHost, you should see the WSGI script say 'Hello World!'. If not, something was not installed properly. Check Apache's error logs.

Upvotes: 1

Related Questions