1

Good day. I am currently trying to host my Django website locally using XAMPP Apache. I have followed several tutorials but one of those works. I was wondering if you could tell me what are the steps I have missed or did wrong. Here is the specs of the installed packages on my Django dev site:

  • Python = 2.7.12, 32-bit
  • Apache = 2.4, 32-bit
  • Visual C++ Version 9
  • OS: Windows 7 64-bit

Here is the procedure I have followed:

  1. Download mod_wsgi from https://code.google.com/archive/p/modwsgi/downloads. I have tried [mod_wsgi-py26-vc9.so, mod_wsgi-py27-vc9.so, mod_wsgi-win32-ap22py27-3.3.so and mod] **but none seems to work.

  2. Rename the mod_wsgi file to mod_wsgi.so and save it to C:/xampp/apache/modules

  3. Run xampp and edit apache httpd.conf file by adding

    LoadModule wsgi_module modules/mod_wsgi.so
    

I have also tried

    LoadModule mod_wsgi modules/mod_wsgi.so

But still have same result. The XAMPP does not display any errors but does not run Apache even after restarting XAMPP and the machine itself. I have also tried to run the app in administrator privileges but it is still not working. Other XAMPP modules are working except Apache.

9
  • Don't use anything from that site, it is old stuff, but can't be removed as Google doesn't allow it. Go read instructions in stackoverflow.com/a/42307082/128141 and build it yourself. You likely need to set MOD_WSGI_APACHE_ROOTDIR to C:/xampp/apache. You can use still use Python 2.7. I would recommend Python 3.5 at least though. Commented Mar 2, 2017 at 8:29
  • Hi sir! Hi have followed the steps that you have suggested to do and installed mod_wsgi. The mod_wsgi-express module-config generated a path for LoadModule { c:/python27/lib/site-packages/mod_wsgi/server/mod_wsgiNone} in Apache and I have added in my httpd.conf, restarted my Apache but it is still not working. Commented Mar 4, 2017 at 5:19
  • If the line literally came out like that, then it isn't working quite right with that old Python version you are using. What are the names of the files in side of the directory c:/python27/lib/site-packages/mod_wsgi/server/mod_wsgi. There should be a file starting with mod_wsgi and ending in .pyd. It is the path to that file which should be argument to LoadModule. I am not sure why it is outputing a dictionary representation for that old Python version. It should be just a single argument of the file path, no braces etc. Commented Mar 4, 2017 at 6:17
  • I have tried to install it once again using easy_install. It generated mod_wsgi-4.5.14-py2.7-win32.egg directory in the site-packages. Inside the directories are EGG-INFO and mod-wsgi directories then inside the mod_wsgi/server I can find the mod_wsgi.pyd. When I run mod_wsgi-express module-config, it prints: LoadModule wsgi_module "c:/python27/lib/site-packages/mod_wsgi-4.5.14-py2.7-win32.egg/mod_wsgi/server/mod_wsgiNone" WSGIPythonHome "c:/python27" I have copied the Loadmodule line in my http.conf, restarted my Apache and its still not working. Commented Mar 4, 2017 at 6:57
  • 1
    Are there any files in the directory at all with .pyd, .pyo or .so extension? Commented Mar 4, 2017 at 9:05

1 Answer 1

1

I have resolved this problem by downloading the binary file at the author's GitHub account and building my own binary file. To do this, I need to extract the downloaded zip file and open the win32 folder and read the README.rst for the instructions.

Excerpt from the instructions:

  1. Know the windows and python versions you are using (Windows 7 32-bit and Python 2.7 in my case)
  2. Install Microsoft C/C++ compiler suitable for your Python version:
    • Python 2.6 - VC9
    • Python 2.7 - VC9
    • Python 3.3 - VC10
    • Python 3.4 - VC10
  3. Start Visual C++ Command Prompt and:

    • Navigate back to the extracted mod_wsgi file and find the appropriate makefile for your combination of Apache and Python (ap22py27-win32-VC9.mk in my case). If you are not sure your Apache version read this for XAMPP or just navigate to localhost for WAMP.
    • Edit the .mk file and define the correct path for APACHE_ROOTDIR and PYTHON_ROOTDIR. Example:

      APACHE_ROOTDIR = C:\xampp\apache

      PYTHON_ROOTDIR = C:\Python27

    • Run nmake -f apXYpyXY-winNN-VC?.mk install. Substitute 'XY' in each case for the version of Apache and Python being used. Substitute 'NN' with either '32' or '64' and substitute '?' with '9' or '10'. Example: nmake -f ap22py27-win32-VC9.mk install. The line builds the mod_wsgi for your platform and installs it to the modules directory of your Apache installation

    • Add the following line in your WAMP/XAMPP http.conf: LoadModule wsgi_module modules/mod_wsgi.so and

      WSGIPythonHome "C:/Python27"

      WSGIPythonPath "ProjectPath"

      WSGIApplicationGroup "%{GLOBAL}"

      WSGIPassAuthorization "On"

    • Restart your Apache or your computer and you're good to go.

Note: There's no need for you to add mod_wsgi in the installed apps of your python since it was already installed in your Apache server

Sign up to request clarification or add additional context in comments.

5 Comments

The stuff in the win32 directory is obsolete, please don't use it. The pip install method is better way to do it and only way that is now supported in any way on Windows. The problem is that for some people the output of mod_wsgi-express module-config is wrong. Work out the correct path of the pyd file and use it. Likely just change None to .pyd. Would have preferred you persist with sorting that out, using the mod_wsgi mailing list to discuss. StackOverflow is worst place to help with this stuff where a discussion is needed.
At a guess the reason still had issues is that Python DLL needed to be force loaded. More recent mod_wsgi-express module-config will produce a LoadFile directive to do just that.
Thanks, sir. I have installed the mod_wsgi using this method 3 months ago and its still working perfectly fine as of the moment. Executing pip install results to an empty file 3 months ago (generated an empty directory in Lib/site-packages) maybe because I am using an older version of Python (v2.4). I just posted this in case this method works with others too.
You sure you meant Python 2.4? Definitely no guarantees that would work. Would be lucky to even work with Python 2.6. Only 2.7 or later okay.
Sorry. I meant 2.7 sir.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.