0

I am running python -m httpserver on Macintosh OS X.

Here's the Python 2.7 code implementing the httpserver:

import CGIHTTPServer
import BaseHTTPServer

class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
    cgi_directories = ["/cgi"]

PORT = 9999

httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()

When I type at the web browser http://localhost:9999/adder.html, I wish to find out the location of the httpd.conf configuration file controlling the behavior of the python 2.7 httpserver module.

There is also an apache24 httpd daemon process running simultaneously. I would guess that they are both using different httpd.conf files in different locations. The httpd.conf file corresponding to the apache24 httpd daemon process is frozen in root read onlypermission which I cannot change so that I make the python 2.7 cgi script executable through the auspices of the cgi module as shown below in the excerpt from this URL, Python script does not run through CGI on Apache2 because Lesley University's information technology specialists have blocked users like myself from running operating system command as sudo .

Without the cgi_module, even code that is chmod +x will not be executable, so uncomment this line:

LoadModule cgi_module libexec/apache2/mod_cgi.so

And change your Directory to look like this (mine works like this):

AllowOverride None Allow from all Require all granted Options ExecCGI AddHandler cgi-script .py

Without this change to the responsible httpd.conf file, I get the following nonsensical message:

Opening adder.cgi , You have chosen to open adder.gui which is a binary file(5.0KB) from httpd://localhost.9999. Would you like to save this file? Cancel or Save

instead of seeing adder.cgi launch a child process.

I am hypothesizing that the python 2.7 httpserver module can reference a non-default httpd.conf in subdirectory relative to the current working directory.

Please let me know if you need more data from me. Thank you for looking at this question.

  • https://stackoverflow.com/questions/17618084/python-cgihttpserver-default-directories – Francis Tuan Jun 05 '17 at 06:36
  • I will test these helpful hints this morning and report back my findings. https://stackoverflow.com/questions/17618084/python-cgihttpserver-default-directories, https://docs.python.org/2/library/cgihttpserver.html and http://tasdikrahman.me/2015/10/20/Running-CGI-Scripts-with-CGIHTTPServer/ – Francis Tuan Jun 05 '17 at 06:40

1 Answers1

0

After reading the ServerFault article https://serverfault.com/questions/168132/setting-up-cgihttpserver-on-osx titled "Setting up CGIHTTPServer on OSX", my Python 2.7 CGI script using /usr/bin/env python was successfully served on a desktop MacIntosh OS X running CGIHTTPServer when I browsed to http://127.0.0.1:8000/WWW/test.py.

Apparently the CGIHTTPServer.py class does not read from the Apache Web server configuration file httpd.conf. Instead the information contained in httpd.conf is "baked into" the CGIHTTPServer.py class source code.

Frank
  • 1,406
  • 2
  • 16
  • 42