Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI in Apache wont work...any thoughts 1

Status
Not open for further replies.

iggystar

IS-IT--Management
Jul 12, 2001
126
US
I've installed Apache and I can run static pages however CGI refuses to run. Here's what I know:

When I try to get a script to run, instead of executing, it just see the text of the script so:
#!/bin/sh
echo Content-type: text/html
ls -la
gets printed instead of giving me an actually directory listing. I'm fairly sure my cgi directory alias is ok too.

When I do an HTTPD -l I can see that I dont have mod_cgi installed. After some grumbling about how moronic it is that the vanilla install doesn't include CGI, I reconfigure and reinstall the whole thing.

I still dont have mod_cgi installed and I still can execute.

Soooo, my question is, why isn't the CGI module installing? I'm stuck. I don't see any errors and the documentation at Apache.Org is so bad that it reaffirms my belief that Satan is alive and well and writing docs for Open Source projects.

Any help would be appreciated.
 
make sure you've got the following lines:
ScriptAlias /cgi-bin/ "actual cgi-bin dir"
AddHandler cgi-script .cgi (or any other extension)

if you want to run the script from other dirs than cgi-bin add ExecCGI to the Options line of that directory.


hope this helps...


:)
 
Yippee

the AddHandler thingy was it. Now I'm having trouble with permissions but that's a CGI problem I'm used to. I should be able to work through that.

Thanks.
 
Aieeeeee

Ok I can't muscle through the permission problem.

I have run chmod 777 on every file and directory that's even remotely concerned with this stupid script and it still tells me I dont have permission to view it.

Can I make my files more promiscuous than CHMOD 777? I'm not sure I'd even want too, already he comes home at all hours of the night, waking up the ROOT directory with all its partying.
 
chmod 777 should do it. what is the exact error message you get?

:)
 
Forbidden
You don't have permission to access /scripts/test.cgi on this server.


--------------------------------------------------------------------------------

Apache/1.3.20 Server at localhost.localdomain Port 80

Here is my script:
#!/bin/sh
echo Content-type: text/html
echo Hello Hello Hello

here is what my permissions look like:
-rwxrwxrwx 1 root root 87 Oct 1 15:43 test.cgi

it runs in this directory:
drwxrwxrwx 2 root root 4096 Oct 1 15:43 scripts

I'm out of ideas and I really want to hit it with a brick (sad thing is, hitting things with bricks almost never makes things better)

 
In a stroke of genius I ran chown -R on my web directory, taking ownership from root and giving it to a less user.


It didn't help.
 
You are gonna have to set permissions through Apache for your CGI bin

Along with the script alias do you set the directory perms in your config???

eg

ScriptAlias /bin/cgi/ "C:/dev/web/newlook3/cgi-bin/"

<Directory &quot;C:/dev/web/newlook3/cgi-bin/&quot;>
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>

apologies for the C: reference but im testin the win32 server atm, but you should get the general idea :)
 
Thanks for the guess but I had checked that already (and I just rechecked it now) and it's what you have listed above.
 
Ok, here's some more info..in my Conf file I have:

<Directory &quot;/usr/ Options indexes followSymLinks multiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>

and I have:

<Directory &quot;/usr/lib/apache/cgi-bin&quot;>
AllowOverride None
Options execCGI
Order allow,deny
Allow from all
</Directory>

but I dont have anything for /usr/ which is where I am keeping my test script.

So I have 3 questions.

1) Do I need to have execCGI turned on in /usr/www? I dont actually run scripts there but I do run scripts from a directory below that.

2) In my Directory &quot;/usr/lib/apache/cgi-bin&quot; section, I added the Options execCGI part. It wasn't there before but it seems like it should be. Do I need to keep that there?

3) Do I need to set up a <Directory> structure for /usr/ I have a script alias set up for it that looks like this:
ScriptAlias /cgi-bin/ /usr/but no <Directory> entry. I tried making one but it didn't help and I dont even know if I should have one.

Thanks. You guys rock.
 
Yes you DO need a <Directory> for the location of your scripts. Apache will only serve from where you tell it to :).
Change:

<Directory &quot;/usr/lib/apache/cgi-bin&quot;>
AllowOverride None
Options execCGI
Order allow,deny
Allow from all
</Directory>

To:

<Directory &quot;/usr/ AllowOverride None
Options execCGI
Order allow,deny
Allow from all
</Directory>

And make sure you restart your server or it wont work.
 
Hi,



The standard cgi bits you'd have in the various sections of httpd.conf are as follows (mostly as given above) :



LoadModule cgi_module modules/mod_cgi.so

AddModule mod_cgi.c


ScriptAlias /cgi-bin/ &quot;/var/
AddHandler cgi-script .cgi
<Directory &quot;/var/
AllowOverride None

Options ExecCGI

Order allow,deny

Allow from all

</Directory>


Try this trivial bash script :

#!/bin/bash
echo Content-type: text/html
#The following (empty) line is necessary!
echo
echo '<html>'
echo '<body>'
echo 'It is now '
date
echo '</body>'
echo '</html>'

Place that in /var/ , do a 'chmod +x /var/ and then test it with
Hopefully it should work...

Regards
 
Hmmm

I dont have:
LoadModule cgi_module modules/mod_cgi.so
or
AddModule mod_cgi.c

What's more...adding breaks everything. HTTPD hates the config file as soon as they are there.

I mentioned in a post above that if I do an HTTP -l to show me all loaded modules, I dont see CGI listed. All I have are:
http_core.c
mod_so.c

I did a very vanilla install of Apache ontop of a clean vanilla install of Red Hat 7.1 so I'm not really sure why something simple like CGI wouldn't be there by default.

Perhaps I need to recompile Apache? This is how I'm installing Apache:
./configure --prefix=/usr/lib/apache
make
make install
The docs make it seem as simple as that but perhaps it's not. Is there something else I should do if I want CGI to work?

Why oh why does linux hate me so? I'm nothing but nice to it! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top