简体   繁体   中英

Internal Server Error trying to run python in apache

I just recently configured my php apache mysql server manually on windows 10 and it's working I don't want use xampp or mammp for educational reason,

I'm now trying to make apache server run python files I download python add path to windows variables, I's show python on cmd, I then configure httpd.conf file and add these line to end of httpd.conf:

AddHandler cgi-script .py
ScriptInterpreterSource Registry-Strict

when I go to my localhost I see this error:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at admin@example.com to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

I open log and error.log in apache folder and see this error:

[Wed Jun 17 20:07:35.229361 2020] [cgi:error] [pid 12420:tid 1336] (OS 2)The system cannot find the file specified.  : [client ::1:49302] couldn't create child process: 720002: index.py
[Wed Jun 17 20:07:35.229361 2020] [cgi:error] [pid 12420:tid 1336] (OS 2)The system cannot find the file specified.  : [client ::1:49302] AH01223: couldn't spawn child process: C:/Apache24/htdocs/pblog/index.py
[Wed Jun 17 20:07:36.549768 2020] [cgi:error] [pid 12420:tid 1336] (OS 2)The system cannot find the file specified.  : [client ::1:49307] couldn't create child process: 720002: index.py
[Wed Jun 17 20:07:36.549768 2020] [cgi:error] [pid 12420:tid 1336] (OS 2)The system cannot find the file specified.  : [client ::1:49307] AH01223: couldn't spawn child process: C:/Apache24/htdocs/pblog/index.py

I found solution here: In your python code you need to add this code and it wont through error again for some reason that I don't know.

#!C:\Python\Python38\python.exe
print("Content-type: text/html")
print("")
print("<html><head>")
print("")
print("</head><body>")
print("Hello.")
print("</body></html>")

your need add this line to top of your file which points to your installed python folder:

#!C:\Python\Python38\python.exe

and keep the structure of html file to run your hello statement:

print("Content-type: text/html")
print("")
print("<html><head>")
print("")
print("</head><body>")
print("Hello.")
print("</body></html>")

without these steps it fails to run. why? I should keep this at every file in my program?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM