I cannot get python files to be served up with Apache 2.2 or 2.4 without a 500 error. I have WebStation installed, python, perl, php, and Apache 2.2 and 2.4 installed.
I can serve up static files just fine with apache. When I try to serve up a most basic "hello world" cgi, I get a 500 error. The error is
[cgid:error] [pid 10076:tid 140542621480832] (2)No such file or directory: AH01241: exec of ['/volume2/Development/WebRepo/cgi-bin/test.py' failed.
Tried to execute both a perl script and a python script. Both run successfully from a command line, but not from served up with Apache (same errors of "no such file..") Also note this is a 500 error, not a 404, so it's seeing the file. I can serve up static HTML files just fine.
The python script couldn't be simpler:
#!/usr/bin/python
print "Content-type: text/html\n\n";
print "Hello, World.";
All files have 755 permissions. The path to python is correct. I'm at a loss as to what to do next.
Python can serve CGI scripts out of the box, using
http.server.CGIHTTPRequestHandler
.On my Synology NAS I have official Python3 package installed (version 3.8.2-0150). I can SSH into NAS as
admin
and add a script:After that I can run it like this (note that
--directory
doesn't have effect for--cgi
so Icd
there):Then on my machine, I can
curl http://nas:8000/cgi-bin/hello.py
.Running on boot
You can run this automatically on boot via the task scheduler.
Control Panel → Task Scheduler → Create → Triggered Task → User-defined script. Fill these on General tab:
And User-defined script on Task Settings tab:
Then you can run it manually. It should also run on reboot.
Permissions
If you want to run the task as
root
, make sure file permissions are correct fromroot
's point of view. In my case there's discrepancy by some reason.