title: Apache CGI in user directory "End of script output before headers"
body: <p>I know there are some questions about this topic, but none seems to solve my issue. See <a href="https://stackoverflow.com/questions/17608627/end-of-script-output-before-headers-hello-pl">this</a> or <a href="https://stackoverflow.com/questions/22644384/django-end-of-script-output-before-headers">this</a> or <a href="https://stackoverflow.com/questions/20039942/end-of-script-output-before-headers-apache-2-4-error">this</a>.</p>
  
  <p>I'm on Linux, Fedora21, and I'm trying to enable per user directory CGI script. I followed <a href="http://httpd.apache.org/docs/2.2/howto/public_html.html#cgi" rel="noreferrer">these</a> instructions, but without success.</p>
  
  <p>I get the error: </p>
  
  <pre><code>[cgi:error] End of script output before headers: test.cgi
  </code></pre>
  
  <p><code>test.cgi</code> is an executable sh file, containing a very simple script:</p>
  
  <pre><code>#!/usr/bin/sh
  
  echo "Content-type: text/plain"
  echo ""
  echo "Hello"
  </code></pre>
  
  <p>which has executable flag and runs without problems from shell.
  I also tried with Python: same result.</p>
  
  <p>I also disabled selinux for good measure.</p>
  
  <p>I also tried setting the <code>debug</code> level to Apache's ErrorLog, but all I get is only "granted" permissions before the error above.</p>
  
  <p>I also configured the <code>/etc/httpd/conf.d/userdir.conf</code> file with</p>
  
  <pre><code>&lt;Directory "/home/*/public_html"&gt;
      AllowOverride All
      Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
      Require all granted
  &lt;/Directory&gt;
  
  &lt;Directory /home/*/public_html/cgi-bin/&gt;
      Options ExecCGI FollowSymLinks
      SetHandler cgi-script
      AddHandler cgi-script .cgi .exe .pl .py .vbs
      Require all granted
      AllowOverride All
  &lt;/Directory&gt;
  </code></pre>
  
  <p>and restarted the server. No success. Everything looks fine to me, I can't understand... What's wrong??</p>
  
  <h1>EDIT:</h1>
  
  <p>I forgot to add that the issue is just for per-user directory: if I move the same script to <code>/var/www/cgi-bin</code> directory, it works as expected.</p>
  
  <h1>EDIT 2:</h1>
  
  <p>The shell does exist:</p>
  
  <pre><code>$ ls /usr/bin/sh
  /usr/bin/sh
  </code></pre>