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.

jonilyn2730
  • 465
  • 9
  • 21
  • 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 http://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. – Graham Dumpleton Mar 02 '17 at 08: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. – jonilyn2730 Mar 04 '17 at 05: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. – Graham Dumpleton Mar 04 '17 at 06: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. – jonilyn2730 Mar 04 '17 at 06:57
  • 1
    Are there any files in the directory at all with ``.pyd``, ``.pyo`` or ``.so`` extension? – Graham Dumpleton Mar 04 '17 at 09:05
  • There is mod_wsgi.pyd but no .pyo or .so extensions. I have also tried to modify the LoadModule path to "c:/python27/lib/site-packages/mod_wsgi-4.5.14-py2.7-win32.e‌​gg/mod_wsgi/server/m‌​od_wsgi.pyd" and its still not working – jonilyn2730 Mar 04 '17 at 12:14
  • Hi Sir. I have solved the problem by downloading the pre-built .whl file from Christoph Golhke's site. Thank you so much for your time :) – jonilyn2730 Mar 04 '17 at 13:06
  • @jonilyn2730, When I typed "mod_wsgi-express module-config" I'm getting response which i need to paste in apache config file."LoadModule wsgi_module "c:/d5300/.env/lib/site-packages/mod_wsgi/server/mod_wsgiNone" WSGIPythonHome " c:/d5300/.env"" What is "mod_wsgiNone" here, what is None refer to? – Mitul Shah Jun 01 '17 at 15:16
  • @MitulShah I think it means, that pip generated an empty mod_wsgi file during the installation. You can verify it by navigating to your python directory\lib\site-packages\mod_wsgi (`C:\Python27\Lib\site-packages\mod_wsgi\server` in my case). I recommend downloading the binary file here at [link ] (https://github.com/GrahamDumpleton/mod_wsgi) and build your own mod_wsgi file. Instructions are available in the win32 folder in the downloaded file – jonilyn2730 Jun 04 '17 at 09:00

1 Answers1

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

jonilyn2730
  • 465
  • 9
  • 21
  • 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. – Graham Dumpleton Jun 04 '17 at 11:37
  • 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. – Graham Dumpleton Jun 04 '17 at 11:41
  • 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. – jonilyn2730 Jun 04 '17 at 12:21
  • 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. – Graham Dumpleton Jun 04 '17 at 20:31
  • Sorry. I meant 2.7 sir. – jonilyn2730 Jun 06 '17 at 03:43