Simple CGI python webserver + php not working
Now similar question(s) has been asked at other places. However, I have tried the suggested solution(s) there and it did not help.
I am running following python CGI webserver:
#!/usr/bin/python
from BaseHTTPServer import HTTPServer
from CGIHTTPServer import CGIHTTPRequestHandler
serve = HTTPServer(("",80),CGIHTTPRequestHandler)
serve.serve_forever()
In the "cgi-bin" directory, following php file "simple.php" is stored:
#!/usr/bin/php
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body&开发者_JAVA技巧gt;
</html>
This file has been given executable permission and executes properly from just the commandline on the server.
Now if I start the server and try to access the page using "http://server/cgi-bin/simple.php", I get just a blank page and I don't see any error on the server stdout.
I looked through the code for CGIHTTPServer.py and I think the problem might be occurring when a process is forked to execute the cgi-bin and the file descriptors (stdin,stdout) are manipulated using dup2. However, I don't know how to get it working. This simple thing has been puzzling me for a few hours and would really appreciate any kind of help.
The server machine is a ubuntu 9.04 box.
#!/usr/bin/php
doesn't make your script run as a CGI; it makes it run as a command-line script. If you have a php-cgi
binary sitting around, use that instead; otherwise, you may have to hack something nasty into the script like:
#!/usr/bin/php
Content-Type: text/html
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
USE: handler.cgi_directories.append('/')
Otherwise your cgi scripts will be executed ONLY if they are '/cgi-bin' or '/htbin' folders as described Here. Basically cgi_directories means to execute cgi from that folder and all subfolders. Hope that helped
精彩评论