This is a duplicate question of this, however none of the answers there worked for me. I have done a lot of research into this and am completely stumped.
I am running a super simple python script called /var/www/cgi/test.py
:
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
import cgitb
print('Content-Type: text/html; charset=utf-8\n')
print("Hello world")
However when I attempt to access this through my server at: https://server.com/cgi/test.py I get the following message:
This obviously doesn't tell me much, so I checked the /var/log/apache2/error.log
file and found the following:
[Tue Jan 25 11:55:10.622681 2022] [cgi:error] [pid 29052] [client REDACTED] AH01215: (8)Exec format error: exec of '/var/www/cgi/test.py' failed: /var/www/cgi/test.py
[Tue Jan 25 11:55:10.623144 2022] [cgi:error] [pid 29052] [client REDACTED] End of script output before headers: test.py
Following my research online, I have tried and done the following:
- I have added the necessary configuration lines into the apache config file at
/etc/apache2/apache2.conf
. It looks like the following (I initially just had theScriptAlias
as I'm fairly certain that's all that's needed but it wasn't working so I added the<Directory>
config too:
# work with the default configuration.
ScriptAlias /cgi/ /var/www/cgi/
<Directory "/var/www/cgi">
Options +ExecCGI
AddHandler cgi-script .cgi .py
</Directory>
# Global configuration
#
"/etc/apache2/apache2.conf" 235L, 7355C
- Restarted apache using
sudo service apache2 restart
since changing the config file - Changed the permissions of
test.py
to bechmod 777 test.py
(overkill I know, but just in case) - Ensured the shebang is correct with
which python3
returning/usr/bin/python3
- I symlinked my
crunchworld.conf
as described in this post
Perhaps even more I'm forgetting. I'm truly at a loss, I feel like I've exhausted every avenue.
Does anyone have any idea why this error is still occurring?