title: Apache2 CGI configuration
body: <p>I'm having trouble accessing a really simple cgi script that I wrote in python and am having too much trouble finding the solution. I have a feeling that it will be quite an easy fix, but I can't figure it out myself.</p>
  
  <p>url: localhost/cgi-bin/test.cgi (I've also tried naming it test.py)
  The error that I'm getting is a simple 404, which I thought the ScriptAlias below would take care of. Further, if I try to access localhost/cgi-bin/ I get a 403: Access Denied. I tried resetting permissions (I'm aware it's stupid) to 777, but no better results.</p>
  
  <p>/etc/apache2/httpd.conf (no special edits to default /etc/apache2/apache2.conf):</p>
  
  <pre><code>ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/
  
  &lt;Directory /usr/local/apache2/cgi-bin/&gt;
      Options +ExecCGI
      AddHandler cgi-script .cgi .py
  &lt;/Directory&gt;
  </code></pre>
  
  <p>/usr/local/apache2/cgi-bin:</p>
  
  <pre><code>.
  └── test.cgi
  </code></pre>
  
  <p>test.cgi:</p>
  
  <pre><code>#!/usr/bin/python 
  import cgi
  #cgi.test()
  print 'Content-type: text/html\n\n'
  print 'test'
  </code></pre>
  
  <p>Further, I've also restarted apache2 after changing httpd.conf file. I can't think of anything else to include besides that I've already looked at:
  <a href="https://stackoverflow.com/questions/7166150/scriptalias-configuration-not-working-in-apache2">ScriptAlias configuration not working in apache2</a>
  but I don't understand what global the author is referencing. I feel pretty strongly that it's an error in one of my configurations, but it seems like the code is pretty straight forward. </p>
  
  <p>If anyone can help me over this hump of stupid, I'd be much appreciative. </p>
  
  <p>Edit:</p>
  
  <p>Error log:</p>
  
  <pre><code>--clip--
  [Thu Sep 26 23:34:59 2013] [error] [client 127.0.0.1] script not found or unable to stat: /usr/lib/cgi-bin/test.cgi
  [Thu Sep 26 23:42:08 2013] [error] [client 127.0.0.1] script not found or unable to stat: /usr/lib/cgi-bin/test.cgi
  </code></pre>
  
  <p>System info:</p>
  
  <pre><code>lsb_release -a
  Distributor ID: Ubuntu
  Description:    Ubuntu 12.04.2 LTS
  Release:    12.04
  Codename:   precise
  uname -a
  Linux #### 3.2.0-39-generic #62-Ubuntu SMP Thu Feb 28 00:28:53 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
  </code></pre>
  
  <p>I think I've found the culprit:</p>
  
  <p>/etc/apache2/sites-enabled/000-default:</p>
  
  <pre><code>1    &lt;VirtualHost *:80&gt;
  2     ServerAdmin webmaster@localhost
  3 
  4     DocumentRoot /var/www
  5     &lt;Directory /&gt;
  6         Options FollowSymLinks
  7         AllowOverride None
  8     &lt;/Directory&gt;
  9     &lt;Directory /var/www/&gt;
  10         Options Indexes FollowSymLinks MultiViews
  11         AllowOverride None
  12         Order allow,deny
  13         allow from all
  14     &lt;/Directory&gt;
  15 
  16     ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  17     &lt;Directory "/usr/lib/cgi-bin"&gt;
  18         AllowOverride None
  19         Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  20         Order allow,deny
  21         Allow from all
  22     &lt;/Directory&gt;
  </code></pre>
  
  <p>Specifically line 16. I never thought to look in this directory</p>