logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Third-party Modules View previous topic :: View next topic
Reply to topic   Topic: How to run Python files without mod_wsgi?
Author
jfha73



Joined: 18 Aug 2011
Posts: 62
Location: New York

PostPosted: Sun 31 May '20 20:34    Post subject: How to run Python files without mod_wsgi? Reply with quote

Hey guys,

I noticed that mod_wsgi uses apache with prefork module and other modules like http2 are not compatible with prefork, is there any other module I can use to run python files? if so, which one and how?

Thanks.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Fri 05 Jun '20 15:51    Post subject: Reply with quote

You can run python as cgi. Then every script that you call from the web needs a shebang line like

Code:
#!/usr/bin/env python


And you need to send the correct header like (note the empty line after the header is needed before the content follows.

#!/usr/bin/env python
# -*- coding: UTF-8 -*-# enable debugging
import cgitb
cgitb.enable() print("Content-Type: text/html;charset=utf-8")
print()
print("Hello World!")
Back to top
jfha73



Joined: 18 Aug 2011
Posts: 62
Location: New York

PostPosted: Sat 06 Jun '20 2:22    Post subject: Reply with quote

I tried as both, CGI and FastCGI and in both cases error.log keeps saying:

FastCGI:
End of script output before headers

CGI:
The system cannot find the file specified.

Any ideas what can be causing this?
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Sat 06 Jun '20 7:05    Post subject: Reply with quote

James Blond wrote:

Code:

#!/usr/bin/env python
              ^

I'm not a Linux person but should that still not be
#!/usr/bin/env/python ?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Sat 06 Jun '20 13:28    Post subject: Reply with quote

The white space is correct. It is like on windows

Code:
where explorer.exe
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Sat 06 Jun '20 13:29    Post subject: Reply with quote

jfha73 wrote:
I tried as both, CGI and FastCGI and in both cases error.log keeps saying:

FastCGI:
End of script output before headers

CGI:
The system cannot find the file specified.

Any ideas what can be causing this?


Are you file chmod +x ?


Please see http://httpd.apache.org/docs/2.4/howto/cgi.html and https://docs.python.org/2/howto/webservers.html

if you still have a question please ask again.
Back to top


Reply to topic   Topic: How to run Python files without mod_wsgi? View previous topic :: View next topic
Post new topic   Forum Index -> Third-party Modules