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

Apache beginner - I need help 5

Status
Not open for further replies.

JennyW

Technical User
Mar 1, 2001
323
CA
Hi my name is Jenny,
I'm a very new beginner to Apache.
I downloaded Apache 1.3.19 on my computer so I could practice inserting very simple CGI scripts on my website.

I've got some problems.

I'm running Apache from a console window (I'm using Windows 98). Apache is up and running and I can see my successful page.

But now what do I do? How can I learn to insert CGI scripts? I've been looking all over the Apache .pdf help files, but I haven't been able to find assistance.

Thanks for reading,
Jenny
 
Simple go to the CGI-BIN directory

usually in the root DIR(C:\Program Files\Apache Group\Apache\cgi-bin)

You can copy the following code in a file(first.c) a execute the program...

Step 1:
-------
#include <stdio.h>
main(){
printf(&quot;content-type: text/html\n\r\n\r&quot;);
printf(&quot;Hello!&quot;);
}
Step 2:
-------
cc -o first first.c

Step 3:
-------
Access the prog. throough browser
 
Hi people,

Since I have Apache do I need to have [tt]Perl[/tt] on my computer to run my CGI scripts?

Thanks,
Jenny

 
Hi again,

ramabrahmam,
You wrote...

...copy the following code in a file(first.c) and execute the program.

Do I save the code within a .txt (text file) or an .html file?

What does first.c mean?

Thanks so much,
Jenny
 
Hi,

I wrote...

Hi people,

Since I have Apache do I need to have Perl on my computer to run my CGI scripts?


Please disgregard the above, I now have Perl on my PC.

However, I still need the above post answered. In what way do I save my CGI scripts?

Thanks taking the time to read this.
Jenny
 
Jenny,

You can save cgi files in the cgi-bin as *.pl or *.cgi. According to how your apache is configured, you may also be able to execute CGi programs from other locations in the web path (place where all of your HTML is accessible).

Hope this helps!

Rninja
 


I was explaining keeping in mind you donot have perl
but any way
you have perl
so no need to write c-programs, and compile agian & again
simply interpreter PERL will do better

i am giving this snippet of a program first.pl

#!PATH_TO_PERL

print &quot;content-type: text/html \n\n&quot;;
print &quot;Hello All!!!&quot;;


Note: PATH_TO_PERL identifies directory to perl

if this not make much, you can have questions
 
Hiee,

Do I save my CGI scripts in my Apache/cgi-bin folder?
Do write my CGI scripts in Notepad?
What kind of file extensions do I give my CGI scripts? Do I need a special program to name the scripts?

Thanks,
Jenny




 
Jenny,
Yes - put your CGI scripts in the cgi-bin
Yes - you can write your CGI scripts in Notepad
Give your scripts an extension of .cgi
If that doesn't work try .pl
You don't need a special program to name them.
In Notepad just use File -> Save As
and give your script a name - e.g. MyScript.cgi
Jub
 
Hi,
Thanks jub, I appreciate your help!

Jenny
 
Hi again!

I'm able to run simple .cgi scripts, like &quot;Hello world&quot;.
I have enabled [tt]ExecCGI[/tt] in my httpd.conf file, but I heard I need to adjust something called the Addhandler in my httpd.conf file.

What is the AddHandler? What does it do?
Is it neccessary?
Where do I go in the httpd.conf file to enable it?

Thanks everyone!
Jenny
 
Jenny,
The following is copied directly from my httpd.conf
Just scroll down the file until you see this...

# AddHandler allows you to map certain file extensions to &quot;handlers&quot;,
# actions unrelated to filetype. These can be either built into the server
# or added with the Action command (see below)
#
# If you want to use server side includes, or CGI outside
# ScriptAliased directories, uncomment the following lines.
#
# To use CGI scripts:
#
#AddHandler cgi-script .cgi

The comments (lines that begin with '#') are pretty self-explanatory, so to Add the handler for 'cgi' files simply 'un-comment' the 'AddHandler cgi-script .cgi' line.
In other words delete the '#' at the front of the line.

Once the file is saved you will need to restart Apache for the change to take effect.
Jub
 
Hi Jub,
Thanks for the help. It was very straightforward and easy to follow.

I edited the the following line in the httpd.conf file. It used to look like this...
[tt]
#AddHandler cgi-script .cgi
[/tt]
But now it's edited to look like the following (deleted #)...
[tt]
AddHandler cgi-script .cgi
[/tt]
But what will this do for me? I'm still kinda unclear on that?
Is adjusting the AddHandler line a neccessary change? Because I was still able to run CGI scripts before making this adjustment.

Thanks Jub!
Jenny
 
AddHandler essentially tells Apache how to handle files with certain extensions. In the case of:
Code:
AddHandler cgi-script .cgi
...you're telling Apache to treat everything with a .cgi extension as a cgi-script (cgi-script is a special term in the Apache configuration). You can tell Apache to treat files with other extensions as cgi-scripts by simply adding them at the end of the line. For instance, to allow both .cgi and .pl files to be run through CGI, you could use:
Code:
AddHandler cgi-script .cgi .pl

There's another directive called ScriptAlias which may have allowed you to use cgi scripts without the handler. What the ScriptAlias directive does is allow everything in a particular directory to be treated as a script, no matter what the extension. Often times, the cgi-bin folder is ScriptAlias'd. If all else fails, refer to to read up on the commands.

Hope this helps clear things up.

brendanc@icehouse.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top