title: Python Cgi script in apache server
body: <p>I think I made some stupid mistake but I am not able to find it.
  Trying to run a simple python cgi script on apache webserver. My Code is</p>
  
  <pre><code>#/usr/bin/env python
  import cgitb
  import cgi
  cgitb.enable()
  print 'Content-Type: text/html'
  print 
  print '&lt;html&gt;'
  print '&lt;head&gt;&lt;title&gt;My first Python CGI app&lt;/title&gt;&lt;/head&gt;'
  print '  &lt;body&gt;'
  print '    &lt;p&gt;something to try&lt;p&gt;'
  print '  &lt;/body&gt;'
  print '&lt;/html&gt;'
  </code></pre>
  
  <p>this code was in /usr/lib/cgi-bin
  I tried to run it by localhost/cgi-bin/test.py
  but it shows <strong>500 INTERNAL SERVER ERROR</strong>.
  I tried with changing its permissions,nothing happened.
  I am able to run html file from /var/www/html/file_name.html
  So I tried moving this in www/ and www/html/ (in both) with making cgi-bin folder and without it, nothing solved.</p>
  
  <p>I had added this in apache2.conf</p>
  
  <pre><code>    &lt;Directory /usr/lib/cgi-bin&gt;
      Options +ExecCGI
      AddHandler cgi-script .cgi .py
      Order allow,deny
      Allow from all
      &lt;/Directory&gt;
  </code></pre>
  
  <p>and var/log/apache2/error.log says <br>
          [Tue Jan 13 22:54:11.422641 2015] [cgid:error] [pid 10157:tid 140434248509184] 
          [client 127.0.0.1:44941] End of script output before headers: test.py <br>
          [Wed Jan 14 00:20:24.434351 2015] [cgid:error] [pid 26512:tid 140434573543296 
          (8)Exec format error: AH01241: exec of '/usr/lib/cgi-bin/test.py' failed <br>
          [Wed Jan 14 00:20:24.434778 2015] [cgid:error] [pid 10158:tid 140434456491776] 
          [client 127.0.0.1:45974] End of script output before headers: test.py</p>