Skip to content

mod_wsgi in python 3.6 and apache 2.4 in xampp 3.2.2 in Windows 8.1 #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vish30 opened this issue Feb 6, 2017 · 30 comments
Closed

mod_wsgi in python 3.6 and apache 2.4 in xampp 3.2.2 in Windows 8.1 #189

vish30 opened this issue Feb 6, 2017 · 30 comments

Comments

@vish30
Copy link

vish30 commented Feb 6, 2017

I am trying to install mod_wsgi module in Windows 8.1, but I am getting following error:

Traceback (most recent call last):
File "setup.py", line 157, in
raise RuntimeError('No Apache installation can be found. Set the 'RuntimeError: No Apache installation can be found. Set the MOD_WSGI_APACHE_ROOTDIR environment to its location.'

I am using apache 2.4 bundled in xampp 3.2.2.
The location of apache instalation folder is "C:\xampp\apache"

@GrahamDumpleton
Copy link
Owner

As the error message says, set the MOD_WSGI_APACHE_ROOTDIR environment variable to its location before running the pip command. So equivalent of:

MOD_WSGI_APACHE_ROOTDIR="C:/xampp/apache"

How you set it will depend on the shell you use.

Use forward slashes, not backwards slashes.

@vish30
Copy link
Author

vish30 commented Feb 9, 2017

Hi @GrahamDumpleton, thanks for your prompt reply. I have tried this. The installation of mod_wsgi was successfull. But when I try to start the server by, it doesn't allow me. Following is the text from command prompt:

D:\Vishesh\DjangoProjects\vishTest>mod_wsgi-express start-server
Usage: mod_wsgi-express command [params]
Commands:
    module-config
    module-location
mod_wsgi-express: error: Invalid command was specified.

@GrahamDumpleton
Copy link
Owner

On Windows mod_wsgi-express is only used to work out the configuration you need to add into your normal Apache instance. You then need to configure the normal Apache instance for your specific WSGI application and use normal method to start Apache. You can't use mod_wsgi-express start-server on Windows.

@vish30
Copy link
Author

vish30 commented Feb 9, 2017

Yes but for that I'll need the mod_wsgi.so file. I am not able to find that for the python version I am using. Please tell where can I find the .so file.

@GrahamDumpleton
Copy link
Owner

Run:

mod_wsgi-express module-config

That command tells you what to put in the Apache configuration file

See section 'Connecting into Apache installation' in:

@vish30
Copy link
Author

vish30 commented Feb 10, 2017

Thanks @GrahamDumpleton, that worked. I have deployed the server on Apache. But, there is one more problem. I am able to access the Django app from my own machine only. If I try opening the django app from another machine on the LAN, the request gets timed out and the page never loads. Please suggest what may be causing this problem.

@vish30
Copy link
Author

vish30 commented Feb 11, 2017

Hi @GrahamDumpleton. I somehow figured out that Firewall was the problem. It was blocking the ports. Thanks a lot for your help.

@vish30 vish30 closed this as completed Feb 11, 2017
@dungneo
Copy link

dungneo commented May 20, 2017

Hi! @GrahamDumpleton.

http://localhost/Hello/index.py

--- index.py
#!C:\Python\Python36-32\python.exe
print("Content-Type: text\html\n")
print("Heelolo ->>>>>>>>")

--- is ok!
Heelolo ->>>>>>>>

but: --- index.py
print("Content-Type: text\html\n")
print("Heelolo ->>>>>>>>")

Server error!
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

---- apache log
[Sat May 20 11:05:46.933792 2017] [win32:error] [pid 10940:tid 1968] [client 127.0.0.1:65351] AH02102: C:/Web/Hello/index.py is not executable; ensure interpreted scripts have "#!" or "'!" first line
[Sat May 20 11:05:46.934292 2017] [cgi:error] [pid 10940:tid 1968] (9)Bad file descriptor: [client 127.0.0.1:65351] AH01222: don't know how to spawn child process: C:/Web/Hello/index.py

--- cmd module config
C:\mod_wsgi-4.5.15>mod_wsgi-express module-config
LoadFile "C:/Python/Python36-32/python36.dll"
LoadModule wsgi_module "C:/Python/Python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"
WSGIPythonHome "C:/Python/Python36-32"

I don't want #!C:\Python\Python36-32\python.exe in first line index.py
because a use virtual path --> send code window -> linux

can u help me!

@GrahamDumpleton
Copy link
Owner

@dungneo Please don't ask a new question in a comment to an existing issue. Create a new issue and I will deal with it there.

@GrahamDumpleton
Copy link
Owner

@dungneo Since you haven't gone on to create a separate question, what I will say is that it appears you haven't actually configure mod_wsgi to say what your WSGI application is. Eg. using WSGIScriptAlias. As a result, due to an existing AddHandler cgi-script .py directive in your configuration, it is being executed as a CGI script and not even using mod_wsgi. Please refer back to the documentation on configuring mod_wsgi at:

@dungneo
Copy link

dungneo commented May 21, 2017

Tks @GrahamDumpleton!
sorry: in .htaccess:
<VirtualHost 127.0.0.1:80>
.....
<Directory "C:/Python/Web">
.....
Options Indexes Includes ExecCGI FollowSymLinks
DirectoryIndex index.py

AddHandler cgi-script .cgi .pl .py
WSGIScriptAlias / C:/Python/Web/

--> it's not working... apache can't start!

but
<VirtualHost 127.0.0.1:80>
.....
<Directory "C:/Python/Web">
.....
Options Indexes Includes ExecCGI FollowSymLinks
DirectoryIndex index.py

#AddHandler cgi-script .cgi .pl .py
#WSGIScriptAlias / C:/Python/Web/

apache ok! it run! but need shebang #!C:\Python\Python36-32\python.exe in first line in index.py to run

i don't want shebang in shebang #!C:\Python\Python36-32\python.exe in first line in index.py to run!
can u help me!
tks!!!!!

@GrahamDumpleton
Copy link
Owner

Are you sure you mean .htaccess file? VirtualHost and WSGIScriptAlias cannot be used in a .htaccess file, they can only be used in the main Apache configuration file.

When you ran:

mod_wsgi-express module-config

did you actually copy the output of that into your Apache configuration file. You can't just run it alone as it does not modify the Apache configuration file for you.

If you didn't add it, then WSGIScriptAlias will generate an error when used in the Apache configuration file.

You don't show the error you get when Apache can't start to confirm what you are doing wrong.

@dungneo
Copy link

dungneo commented May 21, 2017

Tks!
--- cmd module config
**C:\mod_wsgi-4.5.15>**mod_wsgi-express module-config
LoadFile "C:/Python/Python36-32/python36.dll"
LoadModule wsgi_module "C:/Python/Python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"
WSGIPythonHome "C:/Python/Python36-32"

@GrahamDumpleton
Copy link
Owner

Am not asking to see the output.

Did you add:

LoadFile "C:/Python/Python36-32/python36.dll"
LoadModule wsgi_module "C:/Python/Python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"
WSGIPythonHome "C:/Python/Python36-32"

into your main Apache configuration file?

If you do not do that then mod_wsgi will not be loaded and use of WSGIScriptAlias will cause an error.

@dungneo
Copy link

dungneo commented May 21, 2017

Tks! @GrahamDumpleton !!!
httpd.conf
<VirtualHost 127.0.0.1:80>
....

LoadFile "C:/Python/Python36-32/python36.dll"
LoadModule wsgi_module "C:/Python/Python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"
WSGIPythonHome "C:/Python/Python36-32"

@dungneo
Copy link

dungneo commented May 21, 2017

index.py
Server error!
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

in error.log
[Mon May 22 01:23:06.820337 2017] [win32:error] [pid 4224:tid 2044] [client 127.0.0.1:49950] AH02102: C:/Python/Web/Hello/index.py is not executable; ensure interpreted scripts have "#!" or "'!" first line
[Mon May 22 01:23:06.820337 2017] [cgi:error] [pid 4224:tid 2044] (9)Bad file descriptor: [client 127.0.0.1:49950] AH01222: don't know how to spawn child process: C:/Python/Web/Hello/index.py

@GrahamDumpleton
Copy link
Owner

You need to add:

LoadFile "C:/Python/Python36-32/python36.dll"
LoadModule wsgi_module "C:/Python/Python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"
WSGIPythonHome "C:/Python/Python36-32"

into the Apache configuration file at a location which is before any place where you use the mod_wsgi directives. You have added it after the VirtualHost which presumably includes the WSGIScriptAlias directive. That will not work. Move those lines before the VirtualHost, placing it just after any existing LoadModule directives.

@dungneo
Copy link

dungneo commented May 21, 2017

Tks!
in httpd.conf
LoadFile "C:/Python/Python36-32/python36.dll"
LoadModule wsgi_module "C:/Python/Python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"
WSGIPythonHome "C:/Python/Python36-32"

<VirtualHost 127.0.0.1:80>
....
< / VirtualHost >

in error.log
[Mon May 22 01:23:06.820337 2017] [win32:error] [pid 4224:tid 2044] [client 127.0.0.1:49950] AH02102: C:/Python/Web/Hello/index.py is not executable; ensure interpreted scripts have "#!" or "'!" first line
[Mon May 22 01:23:06.820337 2017] [cgi:error] [pid 4224:tid 2044] (9)Bad file descriptor: [client 127.0.0.1:49950] AH01222: don't know how to spawn child process: C:/Python/Web/Hello/index.py

*.py need shebang!!!?!

@GrahamDumpleton
Copy link
Owner

Have you added back the WSGIScriptAlias line?

Remove any line which says:

AddHandler cgi-script .py

as you don't want it and it will cause problems.

Alternatively use a .wsgi extension for Python web application code files that you want to use with mod_wsgi.

@dungneo
Copy link

dungneo commented May 21, 2017

In error.log

mod_wsgi (pid=10972): Target WSGI script 'C:/Python/Web/Hello/index.wsgi' does not contain WSGI application 'application'.

tks!

@GrahamDumpleton
Copy link
Owner

Your script file likely then isn't a WSGI application. The mod_wsgi package is not for running CGI scripts. Use the sample WSGI application of:

def application(environ, start_response):
    status = '200 OK'
    output = b'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

If that works, then go learn about WSGI applications. Preferably go use a framework such as Flask rather than trying to implement WSGI applications from scratch.

@dungneo
Copy link

dungneo commented May 21, 2017

Tks! @GrahamDumpleton so much!

Hello/index.wsgi >>> Hello World!

Do you have skype?! i want ask u about python!?!

@GrahamDumpleton
Copy link
Owner

Sorry, I can't work with you one on one.

If you have questions about Python, trying using StackOverflow or find a local Python user group which you can join.

@dungneo
Copy link

dungneo commented May 21, 2017

ok tks u!

i wan to know best of server for python code:
Apache + WSGI or CherryPy or NGINX or ??

what u choose?!?!

@GrahamDumpleton
Copy link
Owner

You really should focus on getting your WSGI application working first. Implement your WSGI application properly and it should be portable and able to run on any WSGI server. So get your application running and worry about choice of WSGI server later.

@dungneo
Copy link

dungneo commented May 21, 2017

ok! tks @GrahamDumpleton so much!

@vkelk
Copy link

vkelk commented Jan 30, 2018

I had issues with installed different python versions on my Windows 2012 server with apache.
Using this code in httpd.conf helped me:

LoadFile "C:/Python/Python36-32/python36.dll"
LoadModule wsgi_module "C:/Python/Python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"
WSGIPythonHome "C:/Python/Python36-32"

@freakkhurana
Copy link

@GrahamDumpleton i am trying to install mod_wsgi module in Windows 10, but I am getting following error:

Traceback (most recent call last):
File "", line 1 , in
File " c:\user\USER\appdata\local\temp\pip-install-30ia9r6p\mod-wsgi\setup.py", line 158, in
raise RuntimeError('No Apache installation can be found. Set the 'RuntimeError: No Apache installation can be found. Set the MOD_WSGI_APACHE_ROOTDIR environment to its location.'

I am using apache 2.4 bundled in xampp 3.2.2.
The location of apache instalation folder is "E:\xampp\apache"
according to u i ran this command MOD_WSGI_APACHE_ROOTDIR
IT SHOWS IT IS NOT RECOGNIZE AS INTERNAL OR EXTERNAL COMMAND AND IAM USING COMMAND PROMPT SO PLEASE HELP ME

@GrahamDumpleton
Copy link
Owner

Please don't ask question as a comment on existing issues, especially closed issues. Create a new issue.

@GrahamDumpleton
Copy link
Owner

Please don't ask new questions on existing issues, especially one which is closed. I will say though I don't think you will be able to do it. The problem is that Python 2.5 requires a really old MS C/C++ compiler, and it is going to be incompatible with the compiler version Apache 2.4 uses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants