My old CentOS 5 apache server can run Perl script CGI without any problem.
# cat t1.cgi
#!/usr/local/bin/perl
use CGI;
my $cgi = CGI->new();
print $cgi->header;
print "Test\n";
# GET HTTP://www.example.com/cgi/t1.cgi
Test
python scripts can be run under shell without any problem:
# cat t2.cgi
#!/usr/local/bin/python3
print("Content-Type: text/html\n")
print("hello!")
# python3 t2.cgi
Content-Type: text/html
hello!
but failed as a python cgi script:
# GET http://www.example.com/cgi/t2.cgi
<HTML>
<HEAD><TITLE>An Error Occurred</TITLE></HEAD>
<BODY>
<H1>An Error Occurred</H1>
500 Internal Server Error
</BODY>
</HTML>
apache error logs show the error was:
Fatal Python error: _Py_HashRandomization_Init: failed to get random numbers to initialize Python
Python runtime state: preinitialized
Premature end of script headers: t2.cgi
any idea will be appreciated!
fixed it by
mknod -m 444 /dev/random
chmod 444 /dev/urandom
my old centos don't have /dev/random, and the default file mode for urandom was 600, read only by root.