I know there are some questions about this topic, but none seems to solve my issue. See this or this or this.
I\'m on Linux, Fedora21, and I\'m trying to enable per user
Try running your script as the apache user.
There are a number of reasons this could be happening. @JimB mentions problem with the shebang. @premganz mentions problems with debug print statements that fire before your Content-Type string is written. In my case it was a db connection failure. It could be any other problem.
I found the best way to debug this is to run the script directly as the apache user on the command line, and see what errors it gives.
How to run your script as the Apache user
Assuming you're running apache2, and the apache user is www-data, and your cgi script is /myapp/myreport.py - you can do the following.
Allow logins as the www-data user, by changing its default shell. Edit /etc/passwd (temporarily)
sudo su -
cd /etc
cp -p passwd passwd.2017-10-22
emacs passwd # edit file - use your favorite editor
Change:
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
To:
www-data:x:33:33:www-data:/var/www:/bin/bash
Log in as the www-data user
sudo su - www-data
Set any environment vars. Convert your apache SetEnv statements to export statements. In my case, my apache config directory settings has these vars set
SetEnv PYTHONPATH /myapp/lib
SetEnv VCONF /myapp/conf/prod.yaml
Run them as
export PYTHONPATH=/myapp/lib
export VCONF=/myapp/conf/prod.yaml
Then try your cgi script
cd /myapp
./myreport.py
You should see whatever error Apache is experiencing. FIX THEM.
Set the www-data user's default shell back to /usr/sbin/nologin