0

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.

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.

/etc/apache2/httpd.conf (no special edits to default /etc/apache2/apache2.conf):

ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/

<Directory /usr/local/apache2/cgi-bin/>
    Options +ExecCGI
    AddHandler cgi-script .cgi .py
</Directory>

/usr/local/apache2/cgi-bin:

.
└── test.cgi

test.cgi:

#!/usr/bin/python 
import cgi
#cgi.test()
print 'Content-type: text/html\n\n'
print 'test'

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: ScriptAlias configuration not working in apache2 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.

If anyone can help me over this hump of stupid, I'd be much appreciative.

Edit:

Error log:

--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

System info:

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

I think I've found the culprit:

/etc/apache2/sites-enabled/000-default:

1    <VirtualHost *:80>
2     ServerAdmin webmaster@localhost
3 
4     DocumentRoot /var/www
5     <Directory />
6         Options FollowSymLinks
7         AllowOverride None
8     </Directory>
9     <Directory /var/www/>
10         Options Indexes FollowSymLinks MultiViews
11         AllowOverride None
12         Order allow,deny
13         allow from all
14     </Directory>
15 
16     ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
17     <Directory "/usr/lib/cgi-bin">
18         AllowOverride None
19         Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
20         Order allow,deny
21         Allow from all
22     </Directory>

Specifically line 16. I never thought to look in this directory

2
  • 1
    any clues in your apache error log? direcotry listing should be disallowed for the cgi-bin directory, what if you directly access the cgi (localhost/cgi-bin/test.cgi)? Commented Sep 26, 2013 at 20:49
  • I've included a sample of the errors that are showing up. It looks like it's searching the correct directory though. Commented Sep 26, 2013 at 20:54

1 Answer 1

1

Based on your error log, you are not editing the right config, or something. Notice it says /usr/lib/cgi-bin? Just for fun, if you copy your script to /usr/lib/cgi-bin, then try it, does it work? What OS is this apache installed on?

One more thing, is there another ScriptAlias in that config file somewhere? Maybe that is overwriting your mapping of /cgi-bin/?

Sign up to request clarification or add additional context in comments.

5 Comments

You are correct in that I misread the error log. I copied the file into the mentioned directory and it executed like a champ. I guess the larger question is why that directory?
Something is setting it in a config. Thats why I asked what OS. What is the location of the config file you are editing?
/etc/apache2/httpd.conf is what I edited. I'm using the default /etc/apache2/apache2.conf, which doesn't seem to mention that directory, nor do any of the files in /etc/apache2/conf.d/
Every system seems to chop up apache configs in a different way. Are you on linux/unix? find / -name httpd.conf -name apache2.conf -print
in /etc/apache2/sites-enabled there is a file which contained another scriptAlias directive to the directory in my error log. I've fixed the issue thanks to your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.