Configure mod_wsgi 3.3 with Apache2.2 on Windows - mod-wsgi

I was able to compile mod_wsgi for Python 2.5.4. It is now loaded into apache modules. I confirmed it by command
httpd.exe -M
.
.
wsgi_module(shared)
php5_module(shared)
But I am unable to run a test file(hello.wsgi), it is located in folder c:/apache/htdocs/wsgi : so the path of file becomes c:/apache/htdocs/wsgi/hello.wsgi
My hello.wsgi file contains:
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
I added the following lines to httpd.conf:
LoadModule wsgi_module modules/mod_wsgi.so
<IfModule wsgi_module>
WSGIScriptAlias /wsgi/ "c:/apache/htdocs/wsgi/hello.wsgi"
<Directory "c:/apache/htdocs/wsgi">
Order deny,allow
allow from All
</Directory>
</IfModule>
And my Apache Error Log is :
[Sat Nov 19 15:29:32 2011] [warn] pid file C:/apache/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Sat Nov 19 15:29:32 2011] [warn] mod_wsgi: Compiled for Python/2.5.
[Sat Nov 19 15:29:32 2011] [warn] mod_wsgi: Runtime using Python/2.5.4.
[Sat Nov 19 15:29:33 2011] [notice] Apache/2.2.21 (Win32) mod_wsgi/3.3 Python/2.5.4 PHP/5.3.8 configured -- resuming normal operations
[Sat Nov 19 15:29:33 2011] [notice] Server built: Sep 9 2011 10:26:10
[Sat Nov 19 15:29:33 2011] [notice] Parent: Created child process 2296
[Sat Nov 19 15:29:33 2011] [warn] mod_wsgi: Compiled for Python/2.5.
[Sat Nov 19 15:29:33 2011] [warn] mod_wsgi: Runtime using Python/2.5.4.
[Sat Nov 19 15:29:33 2011] [notice] Child 2296: Child process is running
[Sat Nov 19 15:29:33 2011] [notice] Child 2296: Acquired the start mutex.
[Sat Nov 19 15:29:33 2011] [notice] Child 2296: Starting 64 worker threads.
[Sat Nov 19 15:29:33 2011] [notice] Child 2296: Starting thread to listen on port 80.
[Sat Nov 19 15:30:21 2011] [error] [client 127.0.0.1] File does not exist: C:/apache/htdocs/wsgi
Update
I removed the trailing slash from alias, i have moved my wsgi folder from htdocs to apache & created a vhost file:
<VirtualHost 127.0.0.1:80>
<Directory "C:/apache/wsgi">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
ServerName 127.0.0.1
ServerAlias 127.0.0.1
WSGIScriptAlias /wsgi "C:/apache/wsgi/hello.wsgi"
DocumentRoot "C:/apache/wsgi"
ErrorLog "C:/apache/logs/127.0.0.1.err"
CustomLog "C:/apache/logs/127.0.0.1.log" combined
</VirtualHost>
But now my Apache is giving some windows error like:
Faulting application name: httpd.exe, version: 2.2.21.0, time stamp: 0x4e6a3015
Faulting module name: ntdll.dll, version: 6.1.7601.17514, time stamp: 0x4ce7ba58
Exception code: 0xc0000005
Fault offset: 0x00038da9
Faulting process id: 0xc4c
Faulting application start time: 0x01cca6c0f9ccd446
Faulting application path: C:\apache\bin\httpd.exe
Faulting module path: C:\Windows\SysWOW64\ntdll.dll
Report Id: 3ba0b9e0-12b4-11e1-b285-005056c00008
Need Some Help.
Thanks.

This sounds like the error that I had when the Visual C++ 2008 Redistributable (msvcr90.dll) was not installed on the system. But first, please check (with Dependency Walker) that httpd.exe and mod_wsgi.so are using exactly the same msvcr90.dll:
same name
same directory
same version
same timestamp
If they are using different DLL names (e.g. msvcr90.dll and msvcr100.dll) then you must recompile both with the same compiler (e.g. Visual Studio 2008).
If they are using the same DLL name, but different versions or in different directories, then you might be having the same problem that I had, with BitNami DjangoStack.
Because msvcr90.dll was not installed system-wide in C:\Windows\WinSxS, httpd was only able to run at all because there was an "xcopy deployment" of the side-by-side assembly in the same directory as httpd.exe:
Microsoft.VC90.CRT.manifest
msvcr90.dll
If these files had not been present, it would have failed due to a missing dependency on msvcr90.dll, or else with this error:
This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.
(i.e. the DLL was found but without a manifest to make it valid).
Although httpd.exe runs this way, it is not able to reliably load a DLL that also uses msvcr90.dll:
If the DLL has an "xcopy deployment" in its OWN directory, then it will load another copy of the DLL into the process (because it's a different copy of the DLL?). This results in a second heap in the process memory space, which can crash the process if memory is passed between the DLL and httpd (allocated by one and freed by the other). I think this is what you're seeing.
If the DLL does not have an "xcopy deployment" in its own directory, then it will fail to load with a SideBySide or Windows Error Reporting error in the System event log.
You can see more about this kind of problem on Python bug 4120, although this is not a clear, complete and definitive explanation of the problem, and I have not been able to find one yet.
The only reliable way I found to run this stack was to install the Visual C++ 2008 redistributable system-wide, which places a copy of msvcr90.dll in a subdirectory of C:\Windows\WinSxS along with a manifest to make it work.
This should (I think) cause Windows to completely ignore the Microsoft.VC90.CRT.manifest and msvcr90.dll files in the application and DLL directories. Both should use the same DLL in C:\Windows\WinSxS, and it should only be loaded into the process once.

Related

How to get apache to use python3.6 and its modules?

I have a website written in flask and built for python3.6. I am trying to deploy my website using apache and have been having issues.
I installed wsgi using the command:
sudo apt-get install libapache2-mod-wsgi-py3
I installed python3.6 using:
sudo apt-get install python3.6.
Because it is a server dedicated to just this single site I installed my python modules globally using pip3.6 instead of in a virtualenv so all my required/installed modules are located at /usr/local/lib/python3.6/dist-packages/.
I haven't been able to figure out how to get apache to use python3.6 and its modules. By default the version of python apache is using to serve is 3.5, the systems default python3 version (I verified this by printing sys.version_info in my .wsgi file). Because of this it none of my modules are in the path.
After looking around I found the apache config options WSGIPythonHome and WSGIPythonPath. I have tried adding these to my apache.confin different combinations but nothing has worked. Below is what I tried and what the errors were.
# /etc/apache2/apache.conf
WSGIPythonHome /usr/local/lib/python3.6
# /var/log/apache2/error.log
Current thread 0x00007fc69bac4e00 (most recent call first):
[Sun Jan 14 23:02:04.732187 2018] [core:notice] [pid 7139:tid 140490992012800] AH00051: child pid 7154 exit signal Aborted (6), possible coredump in /etc/apache2
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
# /etc/apache2/apache.conf
WSGIPythonHome /usr/local/lib/python3.6
WSGIPythonPath /usr/local/lib/python3.6
# /var/log/apache2/error.log
Current thread 0x00007fc69bac4e00 (most recent call first):
[Sun Jan 14 23:02:04.732187 2018] [core:notice] [pid 7139:tid 140490992012800] AH00051: child pid 7154 exit signal Aborted (6), possible coredump in /etc/apache2
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
# /etc/apache2/apache.conf
WSGIPythonHome /usr/local/
WSGIPythonPath /usr/local/lib/python3.6
# /var/log/apache2/error.log
Current thread 0x00007fc69bac4e00 (most recent call first):
[Sun Jan 14 23:02:04.732187 2018] [core:notice] [pid 7139:tid 140490992012800] AH00051: child pid 7154 exit signal Aborted (6), possible coredump in /etc/apache2
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
# /etc/apache2/apache.conf
WSGIPythonHome /usr/local/lib/python3.6
WSGIPythonPath /usr/local/lib/python3.6
# /var/log/apache2/error.log
Current thread 0x00007fc69bac4e00 (most recent call first):
[Sun Jan 14 23:02:04.732187 2018] [core:notice] [pid 7139:tid 140490992012800] AH00051: child pid 7154 exit signal Aborted (6), possible coredump in /etc/apache2
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
# /etc/apache2/apache.conf
WSGIPythonHome /usr/local/lib/python3.6
WSGIPythonPath /usr/local/lib/python3.6/dist-packages
# /var/log/apache2/error.log
Current thread 0x00007fc69bac4e00 (most recent call first):
[Sun Jan 14 23:02:04.732187 2018] [core:notice] [pid 7139:tid 140490992012800] AH00051: child pid 7154 exit signal Aborted (6), possible coredump in /etc/apache2
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
# /etc/apache2/apache.conf
WSGIPythonPath /usr/local/lib/python3.6
# /var/log/apache2/error.log
Using python version 3.5
Module flask not found
# /etc/apache2/apache.conf
WSGIPythonPath /usr/local/lib/python3.6/dist-packages
# /var/log/apache2/error.log
Using python version 3.5
Module flask not found
Anyway, I think I'm on the right track but can not figure out quite what I am doing wrong. It seems that I am not using the correct PythonHome but I'm not sure what it should be if not one of the above.
Any help would be greatly appreciated.
You can't force mod_wsgi compiled for one Python version to use a different Python installation for a different version. This is because mod_wsgi actually links the Python library for the version it was compiled for, it doesn't just run the python program of some arbitrary version.
The only thing you can do is uninstall mod_wsgi from system packages (which uses Python 3.5) and install mod_wsgi from source code yourself and compile it against Python 3.6.
Also, neither of the paths you gave WSGIPythonHome and WSGIPythonPath were correct anyway. When you install mod_wsgi from source code, don't set those directives as they will continue to screw things up.

Invalid command 'WSGIDaemonProcess', perhaps misspelled or defined by a module not included in the server configuration

In my product, when we upgrade the following error is seen.
Syntax error on line 42 of /etc/httpd/conf.d/25-graphite.conf:
"Invalid command 'WSGIDaemonProcess', perhaps misspelled or defined by a module not included in the server configuration"
Line no 42 of the file /etc/httpd/conf.d/25-graphite.conf is this:
WSGIDaemonProcess wsgi display-name=%{GROUP} processes=5 threads=5
When I went through some of the articles available on stackover flow and returned by google search, most of the articles tend to suggest that
wsgi module is not getting loaded.
Here is the troubleshooting I have done.
The httpd.conf file has following 2 statements
Include "/etc/httpd/conf.d/.load"
Include "/etc/httpd/conf.d/.conf"
List item
The /etc/http/conf.d/ has following 2 files
cat wsgi.*
wsgi.conf
WSGISocketPrefix /var/run/wsgi
wsgi.load
LoadModule wsgi_module modules/mod_wsgi.so
So I am assuming that the code to load the wsgi module is present.
The /etc/httpd/conf.d directory has one more file(25-graphite.conf) which is where the error is reported. Its line no 42 is where the issue is as described above.
Line no 42 of the file /etc/httpd/conf.d/25-graphite.conf is this:
WSGIDaemonProcess wsgi display-name=%{GROUP} processes=5 threads=5
When I read the httpd documentation to understand the below statement from httpd.conf
Include "/etc/httpd/conf.d/.conf*
it is mentioned that the files will be included in alphabetical order. This would mean 25-graphite.conf will be included ahead of wsgi.conf. Can this result in this issue ?
Troubleshooting performed:
1. /etc/init.d/httpd configtest command says the syntax is OK. However there are few warnings.
*[Wed Oct 18 14:54:06 2017] [warn] module proxy_module is already loaded, skipping
[Wed Oct 18 14:54:06 2017] [warn] module proxy_http_module is already loaded, skipping
[Wed Oct 18 14:54:06 2017] [warn] module proxy_ajp_module is already loaded, skipping
[Wed Oct 18 14:54:06 2017] [warn] module headers_module is already loaded, skipping
[Wed Oct 18 14:54:06 2017] [warn] module proxy_module is already loaded, skipping
[Wed Oct 18 14:54:06 2017] [warn] module proxy_balancer_module is already loaded, skipping
[Wed Oct 18 14:54:06 2017] [warn] module proxy_ftp_module is already loaded, skipping
[Wed Oct 18 14:54:06 2017] [warn] module proxy_http_module is already loaded, skipping
[Wed Oct 18 14:54:06 2017] [warn] module proxy_ajp_module is already loaded, skipping
[Wed Oct 18 14:54:06 2017] [warn] module proxy_connect_module is already loaded, skipping
[Wed Oct 18 14:54:06 2017] [warn] NameVirtualHost :443 has no VirtualHosts
/usr/sbin/httpd -M command output has following line which means the module is loaded properly.
wsgi_module (shared)
I need guidance on following.
What should be my approach to troubleshoot this issue further ?
Is there a way to reproduce this issue just by restarting the httpd server instead of carrying out the complete upgrade ?(I am already trying it from my end. This will help me to save time. )
Prathmesh

Unable to start Apache 2.4.18 on Windows

I try to start up my HTTP service by the following procedure:
Startup easyPHP DevServer 16.1
Open Dashboard
Opens on the local machine 127.0.0.1:1111
Try to start the HTTP server using Apache 2.4.18
opens Apache page with VC11 compiler and server with
php version 5.6.17 listening on port 80.
Clicking on the Start button results in a short execution
and then no result. Both the error and access logs are empty.
Any suggestions are appreciated.
In order to properly execute PHP7 you must allready install the Redistribuable Visual C++ V14 (as shown in the PHP7 information detail on easyphp dashboard)
You can find it out here https://www.microsoft.com/download/details.aspx?id=48145
Currently PHP7 is only available in easyPHP in 32bits version, so install the compatible version of VC14.
But soon I hope we can use the x64 PHP7 version, and then you must install the x64 VC14 version
Windows 7 SP1 box, EasyPhp-DevServer-16.1.
Since I have a website to migrate, I decided to update EasyPHP on my computer to start with fresh-up-to-date versions of PHP, Apache, MySQL. Maybe I shouldn't have... the TaskBar icon and admin interface have changed, nothing works like before.
But I am stubborn, and I want it to work. So I try to run something, and it is not. Here are the symptoms, very close to Richard's:
Trying to start Apache 2.4.18, choosing PHP 7.0.2. Click on green "Start" button, it turns into a red "Stop" button. Everything is OK? Nope. Clicking on the "Error log" button, the page comes back to previous state with green "Start" button and nothing in the error log textarea.
OK, so I choose PHP 5.6.17 and click on "Start". I have popups claiming for instance "bz2: Unable to initialize module. Module compiled with module API=20131226. PHP compiled with module API=20121212. These options need to match."
The button turns to red "Stop", and clicking on "Error log" button produces this output:
PHP Warning: PHP Startup: bz2: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: gd: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: mbstring: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: mysql: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: mysqli: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: pdo_mysql: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: pdo_sqlite: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: sockets: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: sqlite3: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: xsl: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
[Mon Feb 22 16:51:45.788809 2016] [mpm_winnt:notice] [pid 3292:tid 236] AH00455: Apache/2.4.18 (Win32) PHP/5.6.17 configured -- resuming normal operations
[Mon Feb 22 16:51:45.789809 2016] [mpm_winnt:notice] [pid 3292:tid 236] AH00456: Apache Lounge VC11 Server built: Dec 11 2015 11:26:53
[Mon Feb 22 16:51:45.789809 2016] [core:notice] [pid 3292:tid 236] AH00094: Command line: '..\\eds-binaries\\httpserver\\apache2418x160222160722\\bin\\eds-httpserver.exe -d C:/BIN/EasyPHP-Devserver-16.1/eds-binaries/httpserver/apache2418x160222160722'
[Mon Feb 22 16:51:45.797809 2016] [mpm_winnt:notice] [pid 3292:tid 236] AH00418: Parent: Created child process 2568
Xdebug requires Zend Engine API version 220131226.
The Zend Engine API version 220121212 which is installed, is outdated.
Since Apache seems to be running, I then launch MySQL. Then I try to run PHPMyAdmin. Here is the resulting message:
phpMyAdmin - Error
The mbstring extension is missing. Please check your PHP configuration.
Of course, since this extension didn't manage to be initialized!
So, here are my complementary questions to Richard's:
What can cause Apache to neither launch nor write any log when choosing PHP 7.0.2?
What can cause Apache to not initialize modules when launching with PHP 5.6.17?
Thanks for any clue,
Seagram
Hello again,
I found out an answer to myself for question 2. that may interest others:
When I installed EasyPHP-DevServer-16.1, I didn't uninstall EasyPHP-DevServer-14.1VC11. In order to have another development working months ago, I have modified my PATH environment variable to point to the php executable in this version.
Now I have removed this path reference in the PATH variable. I also exited from EasyPHP TaskBar icon. THIS IS IMPORTANT in order for this tool to forget the old PATH value. Then I restarted it, clicked on DashBoard again and launched Apache.
Now Apache starts smoothly with PHP 5.6.17 and the error log file contains only:
[Mon Feb 22 17:16:20.295146 2016] [core:warn] [pid 6652:tid 236] AH00098: pid file C:/BIN/EasyPHP-Devserver-16.1/eds-binaries/httpserver/apache2418x160222160722/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Mon Feb 22 17:16:20.313147 2016] [mpm_winnt:notice] [pid 6652:tid 236] AH00455: Apache/2.4.18 (Win32) PHP/5.6.17 configured -- resuming normal operations
[Mon Feb 22 17:16:20.313147 2016] [mpm_winnt:notice] [pid 6652:tid 236] AH00456: Apache Lounge VC11 Server built: Dec 11 2015 11:26:53
[Mon Feb 22 17:16:20.313147 2016] [core:notice] [pid 6652:tid 236] AH00094: Command line: '..\\eds-binaries\\httpserver\\apache2418x160222160722\\bin\\eds-httpserver.exe -d C:/BIN/EasyPHP-Devserver-16.1/eds-binaries/httpserver/apache2418x160222160722'
[Mon Feb 22 17:16:20.321147 2016] [mpm_winnt:notice] [pid 6652:tid 236] AH00418: Parent: Created child process 4052
[Mon Feb 22 17:16:20.895180 2016] [mpm_winnt:notice] [pid 4052:tid 316] AH00354: Child: Starting 64 worker threads.
However, with PHP 7.0.2., Apache keeps on not starting and doesn't trace anything in error log.
Something else is missing...

Tool to upgrade current python installation

I have Python 2.7 installed with ampps. I tried to modify python.conf to make it point to another installation of Python 3.3 but it leads to errors in Apache start up.
LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonPath "C:/Python33/Lib;C:/Python33/Lib/site-packages;C:/Python33/DLLs"
WSGIPythonHome "C:/Python33"
It generates the following error:
[Fri Aug 15 01:48:38.114336 2014] [mpm_winnt:notice] [pid 6084:tid 412] AH00418: Parent: Created child process 5592
File "C:/Python33\lib\site.py", line 173
file=sys.stderr)
^
SyntaxError: invalid syntax
[Fri Aug 15 01:48:39.146395 2014] [mpm_winnt:crit] [pid 6084:tid 412] AH00419: master_main: create child process failed. Exiting.

Apache server doesn't start if try to load mod_wsgi

I'm trying to move my project from the development server to an Apache server.
I run on a Windows 8.1 x64 machine and Python 2.7
I installed Apache 2.2.25 x86 and everything went fine, the server is active; then I downloaded the precompiled mod_wsgi-3.4.ap22.win32-py2.7 (the x86 version to match the version of Apache).
I moved the mod_wsgi.so into the modules folder of the Apache installation and added this line: LoadModule wsgi_module modules/mod_wsgi.so to the httpd config; then, when I try to restart the server it fails leaving this error log:
[Fri Jan 10 18:53:18 2014] [notice] Parent: Received restart signal -- Restarting the server.
[Fri Jan 10 18:53:18 2014] [notice] Child 9772: Exit event signaled. Child process is ending.
httpd.exe: Syntax error on line 130 of C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/httpd.conf: Cannot load C:/Program Files (x86)/Apache Software Foundation/Apache2.2/modules/mod_wsgi.so into server: **Impossible to find the specified module**
[Fri Jan 10 18:53:18 2014] [warn] (OS 995)**I/O operation terminated because of the thread's exit or the application's request.** : winnt_accept: Asynchronous AcceptEx failed.
[Fri Jan 10 18:53:19 2014] [notice] Child 9772: Released the start mutex
[Fri Jan 10 18:53:20 2014] [notice] Child 9772: All worker threads have exited.
[Fri Jan 10 18:53:20 2014] [notice] Child 9772: Child process is exiting
note: the bold (**) parts where in my native language and I simply translated them.
I made sure that the module was actually called mod_wsgi.so so I can't really see where's the problem.
Edit: found the problem. Python (and therfore MySQL pyton mod) were x64 and not x86. Installed the right versions of both and it works just fine.
The key seems to be this:
Cannot load C:/Program Files (x86)/Apache Software Foundation/Apache2.2/modules/mod_wsgi.so into server: **Impossible to find the specified module**
This seems pretty clear. Either that file doesn't exist on your server, or if it does, Apache can't read it. Is it readable by EVERYONE?