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

apache and linux 2

Status
Not open for further replies.

mover50

Programmer
Aug 3, 2004
77
US
I have installed Apache as my web server on linux and trying to use a perl script with cgi.

I am somewhat of a newbie with Apache, linux and perl.

The Apache seems to be ok but I get a file not found when I try to run the perl script.
The url I use is;


hyper//localhost/home/mover50/Linux/chap03/example16

(with hyper actually being http:)

That is where the script file is located and it looks like this:

#! /usr/bin/perl
# The HTML tags are embedded in the here document to avoid using
# multiple print statements
print <<EOF; # here document in a CGI script
Content-type: text/html
<HTML><HEAD><TITLE>Town Crier</TITLE></HEAD>
<H1><CENTER>Hear ye, hear ye, Sir Richard cometh!!</CENTER></H1>
</HTML>
EOF

How do I get this to work? Any help would be most appreciated.

Thanks,

Kent
 
You need to read up on the DocumentRoot and understand that the namespace of the web server is not the same as the filesystem. Basically all URLs are relative to DocRoot.
 
Thanks eric,

I read up on DocumentRoot and all of the other stuff in httpd.conf and at least got it to work part way.

Not sure now if my question is an Apache question or perl or CGI or something else.

I am am learning about perl by example by ellie quigley and am trying to do example16 in chap03. I set up a UserDir public_html in my home directory as is recommended in the httpd.conf and then copy the example16 to the public_html directory.

When I enter localhost/example16, the only the source data displays.

#! /usr/bin/perl
# The HTML tags are embedded in the here document to avoid using
# multiple print statements
print <<EOF; # here document in a CGI script
Content-type: text/html
<HTML><HEAD><TITLE>Town Crier</TITLE></HEAD>
<H1><CENTER>Hear ye, hear ye, Sir Richard cometh!!</CENTER></H1>
</HTML>
EOF

My browser is Mozilla on linux.

How do I get it to execute? Would it better if I asked this on one of the other forums?

Thanks for the help,

Kent
 
Is the file above a .cgi or .pl file? If the file extension is .htm or .html, it won't parse the Perl code.


If i give it a .cgi or .pl extension it tells me it was not found on this server.

Thanks,

Kent
 
Refers to the name of the file on the server.

Sorry, I do not understand what you mean by that?


Kent
 
What's the name of the file that you're trying to execute?
 
What's the name of the file that you're trying to execute?

It is example16.cgi. I have also tried example16.pl.
It is located in /home/mover50/public_html/example16.cgi.

mover50 is my logon name.

Thanks,

Kent
 
If when you view the page in a browser it shows the actual code then Apache doesn't know to execute the script as a cgi program. It thinks you want the file served up like a regular web page. Usually you use ScriptAlias to define a directory that will contain your cgi scripts to execute. You can also use Options +ExecCGI in a Location or Directory. If you need more help, post your httpd.conf file.

 
If when you view the page in a browser it shows the actual code then Apache doesn't know to execute the script as a cgi program. It thinks you want the file served up like a regular web page. Usually you use ScriptAlias to define a directory that will contain your cgi scripts to execute. You can also use Options +ExecCGI in a Location or Directory. If you need more help, post your httpd.conf file.

That helped somewhat. My ScriptAtlas is at the default which is cgi-bin and it tells me to use /var/ I copied my perl sript to that directory and then on my browser entered:

Then it tells me I have an internal server error;

The server encountered an internal error or misconfiguration and was unable to complete your request.

And requests that I contact my server administrator...hehe which is me..

I will post my httpd.conf file if you want, but I feel my problem is somewhere else. I am using the basic defaults and have not changed anything in the httpd.conf file. If the problem is with the .conf file, then it is because I either need to add something or change it.

I think the problem is either with the code, where I placed the code, the URL I specify or the suffix I use on the script. The code is in a previous post.

Open to suggestions.

Thanks,

Kent
 
Ok, now the only problem is that you need an extra line after your header, like so:
Code:
#! /usr/bin/perl
# The HTML tags are embedded in the here document to avoid using
# multiple print statements
print <<EOF; # here document in a CGI script
Content-type: text/html

<HTML><HEAD><TITLE>Town Crier</TITLE></HEAD>
<H1><CENTER>Hear ye, hear ye, Sir Richard cometh!!</CENTER></H1>
</HTML>
EOF

If you haven't already, check out the CGI module. It'll make your life easier with printing headers and html.

 
Ok, now the only problem is that you need an extra line after your header, like so:

I don't see any added code after the header.
I will check out the link you sent and see if can get that cgi example to work.

Thanks,

Kent
 
GREAT BALLS OF FIRE...it worked.

What a difference a blank line can make.

Pray tell, why did the blank line make it work?
Always thought freeform meant freeform.

Thanks I am much happier person :))

Kent

Kent (the worrier)
 
Don't you love when that happens?

But seriously, have you made any changes since it was working? And what error is it giving now?

 
on again, off again and now on again.
I may have been confused about the way I did my URL. I have so many in my history.

For the record this is what works..

which oddly enough is in a round about way is what the book says to use... i.e.

susan/cgi-bin/hello2.cgi

So comlicated and confusing, yet easy when you know exactly how to do it.

Thanks everyone,

Kent
 
Yes, when the instructions say to do it a certain way, and you don't do it that way, you shouldn't be too suprised when it doesn't work. ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top