Tool to upgrade current python installation - apache

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.

Related

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

Boto Import Error when running on apache

I've got an AWS EC2 instance running a flask app through apache.
I've installed boto via pip
I've got a wsgi file set up and if my flask app is a simple hello world it works fine:
#This works
from flask import Flask
app = Flask(__name__)
#app.route("/hello")
def hello():
return "Hello World"
if __name__ == "__main__":
app.run(host='0.0.0.0',port=80)
#http://<PUBLIC_IP>.ap-southeast-2.compute.amazonaws.com/hello
#Hello World
But if I try to import boto:
from boto import dynamodb2
from boto.dynamodb2.table import Table
When I visit http://.ap-southeast-2.compute.amazonaws.com/hello
I get an internal server error. Checking the logs reveals this
[Thu Aug 06 03:20:50 2015] [error] [client 203.220.19.142] mod_wsgi (pid=2988): Target WSGI script '/var/www/myservice/myservice.wsgi' cannot be loaded as Python module.
[Thu Aug 06 03:20:50 2015] [error] [client 203.220.19.142] mod_wsgi (pid=2988): Exception occurred processing WSGI script '/var/www/myservice/myservice.wsgi'.
[Thu Aug 06 03:20:50 2015] [error] [client 203.220.19.142] Traceback (most recent call last):
[Thu Aug 06 03:20:50 2015] [error] [client 203.220.19.142] File "/var/www/myservice/myservice.wsgi", line 4, in <module>
[Thu Aug 06 03:20:50 2015] [error] [client 203.220.19.142] from myservice import app as application
[Thu Aug 06 03:20:50 2015] [error] [client 203.220.19.142] File "/var/www/myservice/myservice.py", line 6, in <module>
[Thu Aug 06 03:20:50 2015] [error] [client 203.220.19.142] from boto import dynamodb2
[Thu Aug 06 03:20:50 2015] [error] [client 203.220.19.142] ImportError: No module named boto
Even though I've already installed boto (pip install boto)
How can I fix this?
I searched yum for related stuff and by running:
yum install python26-boto.noarch
I fixed the issue

mod_wsgi is compiled in one version and running in a different version even after following the given steps

I am getting an error when I run the apache server through my client after going through the log I understood that the mod_wsgi uses python 2.6 during compiling and uses python 2.7 for running. After some research in the Internet I followed the below steps:
You have to recompile mod-python and/or mod-wsgi.
Remove mods
apt-get remove libapache2-mod-python libapache2-mod-wsgi
Get dependencies
apt-get build-dep libapache2-mod-python libapache2-mod-wsgi
Build mod-python
mkdir /tmp/python
cd /tmp/python
apt-get source libapache2-mod-python
cd libapache2-mod-python-[x.x.x]
dpkg-buildpackage -rfakeroot -b
Build mod-wsgi
mkdir /tmp/wsgi
cd /tmp/wsgi
apt-get source libapache2-mod-wsgi
cd mod-wsgi-[x.x.x]
dpkg-buildpackage -rfakeroot -b
Install newly compiled packages
dpkg -i /tmp/python/libapache2-mod-python-[x.x].deb /tmp/wsgi/libapache2-mod-wsgi-[x.x].deb
It was of no use, now the version has changed to 3.2, I am worried about the space being consumed through the above steps and now the compiling python has changes to python 3.2 from 2.6 but the python used for running is still 2.7. please help me with what to do ? to get back my apache server running successfully.
error.log::::
[Wed Aug 21 11:48:11 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Wed Aug 21 11:48:11 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Wed Aug 21 11:48:11 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Wed Aug 21 11:48:36 2013] [notice] caught SIGTERM, shutting down
[Wed Aug 21 22:48:29 2013] [error] child process 1226 still did not exit, sending a SIGKILL
[Wed Aug 21 22:48:30 2013] [notice] caught SIGTERM, shutting down
[Wed Aug 21 22:56:17 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Wed Aug 21 22:56:17 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Wed Aug 21 22:56:17 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Thu Aug 22 01:32:12 2013] [notice] caught SIGTERM, shutting down
[Thu Aug 22 01:32:26 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Thu Aug 22 01:32:26 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Thu Aug 22 01:32:26 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Thu Aug 22 04:04:48 2013] [notice] child pid 11212 exit signal Segmentation fault (11)
[Thu Aug 22 04:04:48 2013] [notice] caught SIGTERM, shutting down
[Thu Aug 22 04:04:56 2013] [notice] mod_python: Creating 8 session mutexes based on 6 max processes and 25 max threads.
[Thu Aug 22 04:04:56 2013] [notice] mod_python: using mutex_directory /tmp
[Thu Aug 22 04:04:56 2013] [warn] mod_wsgi: Compiled for Python/3.2.3.
[Thu Aug 22 04:04:56 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Thu Aug 22 04:04:56 2013] [notice] Apache/2.2.22 (Ubuntu) mod_python/3.3.1 Python/2.7.3 mod_wsgi/3.3 configured -- resuming normal operations
Thank you
Don't load mod_python and mod_wsgi at the same time if you don't need to. They are likely compiled against different Python versions. See the following for an explanation of the mismatch you are seeing.
http://code.google.com/p/modwsgi/wiki/InstallationIssues#Python_Version_Mismatch
If you do need both, they must both be compiled for the same version.
These days there is generally no good reason to be using mod_python for new projects.
Just to add
I have uninstalled libapache2-mod-python
sudo apt-get remove libapache2-mod-python
which I have installed
then I have overcome the above error
[Thu Aug 22 01:32:26 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Thu Aug 22 01:32:26 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.

DigitalOcean Deploy - "ImportError: No module named flask.ext.wtf"

All, I'm trying to deploy a simple page using flask/apache on a digitalocean server. It all works fine locally, but not on the server.
__init__.py contains the statement:
from flask.ext.wtf import Form,TextField
try_me.wsgi is:
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/try_me/")
from try_me import app as application
application.secret_key = 'Add your secret key'
Getting the following error (from /var/log/apache2/error.log):
[Mon Jul 29 14:16:50 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Mon Jul 29 14:16:50 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Mon Jul 29 14:16:50 2013] [notice] Apache/2.2.22 (Debian) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Mon Jul 29 14:16:57 2013] [error] [client 74.66.8.166] mod_wsgi (pid=2920): Target WSGI script '/var/www/try_me/try_me.wsgi' cannot be loaded as Python module.
[Mon Jul 29 14:16:57 2013] [error] [client 74.66.8.166] mod_wsgi (pid=2920): Exception occurred processing WSGI script '/var/www/try_me/try_me.wsgi'.
[Mon Jul 29 14:16:57 2013] [error] [client 74.66.8.166] Traceback (most recent call last):
[Mon Jul 29 14:16:57 2013] [error] [client 74.66.8.166] File "/var/www/try_me/try_me.wsgi", line 7, in <module>
[Mon Jul 29 14:16:57 2013] [error] [client 74.66.8.166] from try_me import app as application
[Mon Jul 29 14:16:57 2013] [error] [client 74.66.8.166] File "/var/www/try_me/try_me/__init__.py", line 4, in <module>
[Mon Jul 29 14:16:57 2013] [error] [client 74.66.8.166] from flask.ext.wtf import Form
[Mon Jul 29 14:16:57 2013] [error] [client 74.66.8.166] File "/usr/local/lib/python2.7/dist-packages/flask/exthook.py", line 87, in load_module
[Mon Jul 29 14:16:57 2013] [error] [client 74.66.8.166] raise ImportError('No module named %s' % fullname)
[Mon Jul 29 14:16:57 2013] [error] [client 74.66.8.166] ImportError: No module named flask.ext.wtf
I was able to import manually in a python interpreter (under virtualenv):
Python 2.7.3 (default, Jan 2 2013, 16:53:07)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from flask.ext.wtf import Form
>>> Form
<class 'flask_wtf.form.Form'>
Any ideas on how to proceed here?
SOLUTION (Following Cathy's advice above, and dAnjou below), virtualenv must be activated from the wsgi script. Adding activate_this execution solved the problem:
#!/usr/bin/python
activate_this = '/var/www/try_me/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
import sys
..

Configure mod_wsgi 3.3 with Apache2.2 on Windows

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.