CGIHTTPServer webserver running php scripts

M

mpc

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 to http://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?
 
M

Michael Palmer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top