CGIHTTPServer webserver running php scripts

Michael Palmer m_palmer45 at yahoo.ca
Mon Sep 15 19:28:52 EDT 2008


On Sep 15, 5:25 pm, mpc <mcoh... at gmail.com> wrote:
> hello,
> how does one run a PHP page with a python webserver?
>
> Lets say i have a simple python web server running
> /path/webserver.py
> #!/usr/bin/env
> python
> from BaseHTTPServer import HTTPServer
> from CGIHTTPServer import CGIHTTPRequestHandler
> serve = HTTPServer(("",8080),CGIHTTPRequestHandler)
> serve.serve_forever()
>
> Also lets say i am interested in hosting a simple.php in the cgi-bin
> directory.
> /path/cgi-bin/simple.php
> <html>
> <head>
> <title>A simple php script.</title>
> </head>
> <? print(Date("1 F d, Y")); ?>
> <body>
> </body>
> </html>
>
> The webserver starts up and hosts html and python cgi's just fine
> but nothing will come up when we go tohttp://localhost:8080/cgi-bin/simple.php
>
> I get the following errors.
> with normal user
> localhost:path user$ python webserver.py
> localhost - - [15/Sep/2008 16:17:59] "GET /cgi-bin/example.php HTTP/
> 1.1" 200 -
> Traceback (most recent call last):
>   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/CGIHTTPServer.py", line 251, in run_cgi
>     os.execve(scriptfile, args, os.environ)
> OSError: [Errno 8] Exec format error
> localhost - - [15/Sep/2008 16:17:59] CGI script exit status 0x7f00
>
> localhost:path user$ sudo python webserver.py
> Password:
> localhost - - [15/Sep/2008 16:18:29] "GET /cgi-bin/example.php HTTP/
> 1.1" 200 -
> Traceback (most recent call last):
>   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/CGIHTTPServer.py", line 251, in run_cgi
>     os.execve(scriptfile, args, os.environ)
> OSError: [Errno 13] Permission denied
>
> Is there something I can add to my python webserver so that it will
> properly run php files?

It seems you have to set the executable permission on your php file. I
suppose you have php set up for cgi and the shebang line in your php
file? From a cursory glance through CGIHTTPServer.py it seems that it
should work.



More information about the Python-list mailing list