2

I have the following CGI script which launches a Flask web application. However all I get is a 500 Internal Server Error

#!/home/xxx/public_html/cgi-bin/venv/bin/python
import site
site.addsitedir("/home/xxx/public_html/cgi-bin/venv/lib/python2.7/site-packages")

from wsgiref.handlers import CGIHandler
from app import app

CGIHandler().run(app)

I get the following errors in Apache's error_log:

[Fri Jan 27 09:53:18.052981 2017] [cgi:error] [pid 20660] [client aa.bb.cc.dd:58331] AH01215: suexec policy violation: see suexec log for more details: /home/xxx/public_html/cgi-bin/app.cgi, referer: http://xxx.io/

[Fri Jan 27 09:53:18.053176 2017] [cgi:error] [pid 20660] [client aa.bb.cc.dd:58331] End of script output before headers: app.cgi, referer: http://xxx.io/

And the following error in suexec_log:

[2017-01-27 09:53:18]: uid: (522/xxx) gid: (534/xxx) cmd: app.cgi

[2017-01-27 09:53:18]: (2)No such file or directory: exec failed (app.cgi)

All the files should be in all the right places. Not sure how to proceed with debugging. If it helps, I do have root access to this server.

Erik Johnson
  • 858
  • 1
  • 7
  • 29
  • it has problem with `/home/xxx/public_html/cgi-bin/app.cgi`. If file exists then it may have problem with privilages - Apache mostly runs as user `www-data` and `www-data` may not have access to your folders/files. – furas Jan 27 '17 at 10:41
  • I'm using `suexec`, so shouldn't be a problem – Erik Johnson Jan 28 '17 at 00:42
  • Problem #1 was my CGI script had Windows line endings. Now I'm getting `(13)Permission denied: exec failed (app.cgi)` – Erik Johnson Jan 28 '17 at 04:20

1 Answers1

3

Two problems:

  1. The .cgi file contained Windows line endings
    • Solved by :set ff=unix in Vim
  2. The python interpreter in my virtualenv was not set as executable

Once I solved those, it works like a charm!

Erik Johnson
  • 858
  • 1
  • 7
  • 29
  • OMG, I was banging my head against the wall for hours because I had the exact same CGI script running a demo flask app before I deployed a much larger implementation. But I thought, well, I'll give this a try and it worked. No idea why it worked before but not after changing the rest of the app, but this fixed it. – David Scott Sep 20 '21 at 22:02