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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enabling CGI scripts

Status
Not open for further replies.

Kegnut

Technical User
Apr 18, 2001
106
US
Hello.

First off, I am VERY NEW to apache, so please forgive me.

I am running Apache 1.3.19 on Linux RH 7.1. I wrote a little test script that looks a lil something like this:

bash# vi roo.cgi
#!/usr/bin/perl
print "This is a test";

Now, how is it when I go to the URL ( it prints out the whole script instead of executing it.

I have added ExecCGI to the options, And that doesn't seem to do the trick. When I add the "AddHandler cgi-script .cgi" I get an error. Any help would be greatly appreciated.

Thanks,
J
 
Hi,



You have to have a content-type statement like this :



print "Content-type: text/plain\n\n";



The following should
demonstrate :


#!/usr/bin/perl

##

## printenv -- demo CGI program which just prints its environment

##



print "Content-type: text/plain\n\n";

foreach $var (sort(keys(%ENV))) {

$val = $ENV{$var};

$val =~ s|\n|\\n|g;

$val =~ s|"|\\"|g;

print "${var}=\"${val}\"\n";

}





You also need to 'chmod +x scriptname.cgi' .



To activate cgi you have to uncomment the AddHandler directive in httpd.conf, e.g.

AddHandler cgi-script .cgi .pl

and define the physical path of the cgi directory :



ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"

You also need :



LoadModule cgi_module         modules/mod_cgi.so



and



AddModule mod_cgi.c



in the appropriate sections of httpd.conf . Also you would need something like the following for the cgi-bin directory :



<Directory &quot;/usr/local/apache/cgi-bin&quot;>

    AllowOverride None

    Options ExecCGI

    Order allow,deny

    Allow from all

</Directory>



Hope this helps
 
Thanks!

It was the &quot;Content-type: text/plain\n\n&quot;; line that I had left out. What exactly is that and why do I need it?

Thanks again!
Josh
 
Hi,



Its MIME content-type information thats used to identify the type of information in the resource. A http client (browser) sends an accept header saying what mime-types it can handle - can be html, plain text, gif, pdf , etc., etc.



Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top