How to install mod_wsgi on Windows+XAMPP in 2017

Viewed 8803

Im a trying (hard) to set up environment for Django app on Windows with XAMPP.

What I have:

  • Windows 7 64bit
  • Apache/2.4.25 (Win32)
  • Python 3.6.1 platform.architecture() = ('64bit', 'WindowsPE')
  • Cygwin 2.9.0(0.318/5/3)
  • MOD_WSGI_APACHE_ROOTDIR pointing to apache dir in XAMPP installation

What I did already:

Tried to install with pip install mod_wsgi but it didn't work because apxs could not be found. So I've installed httpd-devel in Cygwin. Now it rises collect2: error: ld returned 1 exit status error with massive output that I can't understand.

According to this, I've downloaded WHL file, exctracted PYD file but when I want to run Apache I get syntax error on LoadModule wsgi_module modules/mod_wsgi.pyd: Cannot load modules/mod_wsgi.pyd into server: The specified module could not be found.. I've tried 3 versions of WHL.

I'm new to Python/Django and WSGI and I'm already done ;-)

2 Answers

My first attempt was creating a virtualenv using python3.6.2 (32 bits) and trying to install mod_wsgi on a vs2015_x86 command prompt, after set MOD_WSGI_APACHE_ROOTDIT and doing pip install mod_wsgi i'd get a bunch of unresolved errors.

Then I thought maybe it was required a 64bits version of python so I installed python3.6.2 (64 bits), created a virtualenv and opened a vs2015 x64 command prompt and the installation was smooth, ie:

(py362_64) D:\sources\personal\python\framework\engine\tests\test>set MOD_WSGI_APACHE_ROOTDIR=C:/wamp/bin/apache/apache2.4.9

(py362_64) D:\sources\personal\python\framework\engine\tests\test>pip install mod_wsgi                               
Collecting mod_wsgi                                                                                                  
  Using cached mod_wsgi-4.5.18.tar.gz                                                                                
Building wheels for collected packages: mod-wsgi                                                                     
  Running setup.py bdist_wheel for mod-wsgi ... done                                                                 
  Stored in directory: C:\Users\KneDa\AppData\Local\pip\Cache\wheels\75\86\b4\6e5bf5e1cea623c0578dc5d0424a32014f33cd3
bfde193d987                                                                                                          
Successfully built mod-wsgi                                                                                          
Installing collected packages: mod-wsgi                                                                              
Successfully installed mod-wsgi-4.5.18                                                                               

One thing you need to be careful about is how you set the MOD_WSGI_APACHE_ROOTDIR, using / instead \ and not enclosing on double quotes.

EDIT:

Also tried to install mod_wsgi on a python3.6.2 (64bits) on a normal cmd prompt (no visual studio compiler available) without setting MOD_WSGI_APACHE_ROOTDIR and the wheel has been installed succesfully, ie:

(foo) C:\whatever>pip install mod_wsgi
Collecting mod_wsgi
Installing collected packages: mod-wsgi
Successfully installed mod-wsgi-4.5.18
Related