title: CGIHTTPRequestHandler run php or python script in python
body: <p>I'm writing a simple python web-server on windows..</p>
  
  <p>it works but now I want to run dynamic scripts (php or py) and not only html pages..</p>
  
  <p>here is my code:</p>
  
  <pre><code>from BaseHTTPServer import HTTPServer
  from CGIHTTPServer import CGIHTTPRequestHandler
  
  class RequestsHandler(CGIHTTPRequestHandler):
      cgi_directories = ["/www"] #to run all scripts in '/www' folder
      def do_GET(self):
          try:
              f = open(curdir + sep + '/www' + self.path)
              self.send_response(200)
              self.send_header('Content-type', 'text/html')
              self.end_headers()
              self.wfile.write(f.read())
              f.close()
          except IOError:
              self.send_error(404, "Page '%s' not found" % self.path)
  
  def main():
      try:
          server = HTTPServer(('', 80), RequestsHandler)
          server.serve_forever()
      except KeyboardInterrupt:
          server.socket.close()
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>if I put php code in www folder I get the page but the code isn't interpreted</p>
  
  <p>what I have to do? thanks</p>