Web Servers on Unix and Linux - First cgi script on Apache server.

This is Interesting: Free IT Magazines  
Home > Archive > Web Servers on Unix and Linux > October 2006 > First cgi script on Apache server.





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author First cgi script on Apache server.
Vinay Nagrik

2006-09-25, 7:24 pm

Hello Group,

I am trying to run my first cgi script and configured my server in the
httpd.conf file as

ScriptAlias /cgi-bin/ "/var/www/html"

AddHandler cgi-script .cgi

/var/www/html/ is the directory where my first cgi script resides and
reads as

#!/usr/bin/perl -w
print "Content-Type: text/html\n\n"
print "Howdy, world!\n"

The permission in the directory for the script is 755

However, when I type

http://<server-name>/first.cgi

The browser comes back with

Forbidden,

You don't have permissions to run first.cgi.

Can someone help in pointing out the mistakes I did and where.

Thanks.

nagrik

Max Dittrich

2006-09-25, 7:25 pm

Am 25 Sep 2006 14:05:49 -0700 schrieb Vinay Nagrik:

> Hello Group,
>
> I am trying to run my first cgi script and configured my server in the
> httpd.conf file as
>
> ScriptAlias /cgi-bin/ "/var/www/html"
>
> AddHandler cgi-script .cgi


You're mixing up two ways to enable CGIs.

The traditional one:

ScriptAlias /cgi-bin/ "/some/dir/cgi-bin/"
# ^ ^ !!!
<Directory /some/dir/cgi-bin>
Order Allow,Deny
Allow from All
</Directory>

and the logical one:

<Directory /some/dir/below/documentroot>
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>

>
> /var/www/html/ is the directory where my first cgi script resides and
> reads as
>
> #!/usr/bin/perl -w
> print "Content-Type: text/html\n\n"
> print "Howdy, world!\n"
>
> The permission in the directory for the script is 755


Script and permissions are looking fine.

>
> However, when I type
>
> http://<server-name>/first.cgi
>
> The browser comes back with
>
> Forbidden,
>
> You don't have permissions to run first.cgi.
>
> Can someone help in pointing out the mistakes I did and where.


If your server is configured to serve CGIs from the directory
/var/www/cgi-bin/ move your script to this location and point your browser
to http://<server-name>/cgi-bin/first.cgi .

Otherwise, if you prefer to store your CGIs in the base directory
(DocumentRoot) add the following sequence to enable execution of CGIs:

<Directory /var/www/html>
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>

If you still got some 500-erros you should read about the special feature
"suexec".

hf,
..max
Vinay Nagrik

2006-09-28, 1:17 pm

Max Dittrich wrote:
> Am 25 Sep 2006 14:05:49 -0700 schrieb Vinay Nagrik:
>
>
> You're mixing up two ways to enable CGIs.
>
> The traditional one:
>
> ScriptAlias /cgi-bin/ "/some/dir/cgi-bin/"
> # ^ ^ !!!
> <Directory /some/dir/cgi-bin>
> Order Allow,Deny
> Allow from All
> </Directory>
>
> and the logical one:
>
> <Directory /some/dir/below/documentroot>
> Options +ExecCGI
> AddHandler cgi-script .cgi
> </Directory>
>
>
> Script and permissions are looking fine.
>
>
> If your server is configured to serve CGIs from the directory
> /var/www/cgi-bin/ move your script to this location and point your browser
> to http://<server-name>/cgi-bin/first.cgi .
>
> Otherwise, if you prefer to store your CGIs in the base directory
> (DocumentRoot) add the following sequence to enable execution of CGIs:
>
> <Directory /var/www/html>
> Options +ExecCGI
> AddHandler cgi-script .cgi
> </Directory>
>
> If you still got some 500-erros you should read about the special feature
> "suexec".
>
> hf,
> .max


Max,

I made necessary changes and yes the 500 error has gone. However, now
I have full
content of the file itself. And the browser prints thew following

**************************
#!/usr/bin/perl -w
print "Content-Type: text/html\n\n"
print "Howdy, world!\n"
********************

I thought it should just pring

Howdy, world

only not the content of the files. How can I correct this problem.

Thanks.

arun

Werner Zumwinkel

2006-09-30, 7:23 am

Hi,

I have the exact same Problem with my installation, too. What is the
suexec_log ist telling you? You shoult find it at

/var/log/apache2/

or similar directory...in my case, no errors are written into the logfiles.

And i have no idea how to go one...



Yours Sincerly,

Werner

>
> I made necessary changes and yes the 500 error has gone. However, now
> I have full
> content of the file itself. And the browser prints thew following
>
> **************************
> #!/usr/bin/perl -w
> print "Content-Type: text/html\n\n"
> print "Howdy, world!\n"
> ********************
>
> I thought it should just pring
>
> Howdy, world
>
> only not the content of the files. How can I correct this problem.
>
> Thanks.
>
> arun
>

Vinay Nagrik

2006-10-02, 7:37 pm


Werner Zumwinkel wrote:
> Hi,
>
> I have the exact same Problem with my installation, too. What is the
> suexec_log ist telling you? You shoult find it at
>
> /var/log/apache2/
>
> or similar directory...in my case, no errors are written into the logfiles.
>
> And i have no idea how to go one...
>
>
>
> Yours Sincerly,
>
> Werner


I have my logs in 'httpd' directory, however it seems to be the server
log with 200 OK message.

Can someone tell us why the script is not executed and why we(I) get
all three lines of the
file and not the intended line

"Howdy, World"

only.

Thanks.

arun
[vbcol=seagreen]

Vinay Nagrik

2006-10-02, 7:37 pm


Werner Zumwinkel wrote:
> Hi,
>
> I have the exact same Problem with my installation, too. What is the
> suexec_log ist telling you? You shoult find it at
>
> /var/log/apache2/
>
> or similar directory...in my case, no errors are written into the logfiles.
>
> And i have no idea how to go one...
>
>
>
> Yours Sincerly,
>
> Werner


I have my logs in 'httpd' directory, however it seems to be the server
log with 200 OK message.

Can someone tell us why the script is not executed and why we(I) get
all three lines of the
file and not the intended line

"Howdy, World"

only.

Thanks.

arun
[vbcol=seagreen]

Max Dittrich

2006-10-04, 7:25 am

Hi,

sorry this thread went out of my sight.

Am 2 Oct 2006 13:47:15 -0700 schrieb Vinay Nagrik:

> Werner Zumwinkel wrote:
>
> I have my logs in 'httpd' directory, however it seems to be the server
> log with 200 OK message.
>
> Can someone tell us why the script is not executed and why we(I) get
> all three lines of the
> file and not the intended line
>
> "Howdy, World"
>
> only.


- Where did you stored your script?
- What's the name of your script?
- What apache configuration apllies to the containing directory?
- Are you using some kind of VirtualHost-Setup?

..max
Vinay Nagrik

2006-10-04, 7:29 pm


Max Dittrich wrote:
> Hi,
>
> sorry this thread went out of my sight.
>
> Am 2 Oct 2006 13:47:15 -0700 schrieb Vinay Nagrik:
>
>
> - Where did you stored your script?


A. I stored my script in /var/www/html directory. And the
configuration in httpd.conf reads
as

ScriptAlias /cgi-bin/ "var/www/html/"

<Directory "/var/www/html"> # Notice no "/" here at the end of html
Order allow, deny
Allow from all
</Directory>

The script configuration is as typed no spelling mistakes, nothing
removed, nothing added.

> - What's the name of your script?


A. The name is first.cgi. And the content are

!#/usr/bin/perl -w
print "Content-Type: text/html\n\n"
print "Howdy, world\n"


> - What apache configuration apllies to the containing directory?


A. As mentioned above
> - Are you using some kind of VirtualHost-Setup?


A. No

However, when I do a post to the script it prints whole content of file
first.cgi verbatum and
not just a single line to the browser as (Howdy,, world) as was
expected.

Thanks.

arun

>
> .max


Max Dittrich

2006-10-05, 7:21 am

Hi,

[..]

>
> A. I stored my script in /var/www/html directory. And the
> configuration in httpd.conf reads
> as
>
> ScriptAlias /cgi-bin/ "var/www/html/"
>
> <Directory "/var/www/html"> # Notice no "/" here at the end of html
> Order allow, deny
> Allow from all
> </Directory>
>
> The script configuration is as typed no spelling mistakes, nothing
> removed, nothing added.
>
>
> A. The name is first.cgi. And the content are
>
> !#/usr/bin/perl -w
> print "Content-Type: text/html\n\n"
> print "Howdy, world\n"
>
>
>
> A. As mentioned above
>
> A. No
>
> However, when I do a post to the script it prints whole content of file
> first.cgi verbatum and
> not just a single line to the browser as (Howdy,, world) as was
> expected.


What URL are you using in your request?

I think "/var/www/html" is your basic publishing directory AKA DocumentRoot
and because you're mapping URLs beginning with '/cgi-bin/' into your
DocumentRoot there are two ways requesting your script:
http://<your-host>/first.cgi
and http://<your-host>/cgi-bin/first.cgi

Using the second one should execute your script, but _please_ read about
the security issues mentioned in
http://httpd.apache.org/docs/2.0/mo...tml#scriptalias .

..max
Vinay Nagrik

2006-10-05, 7:21 pm

Max Dittrich wrote:
> Hi,
>
> [..]
>
>
> What URL are you using in your request?
>
> I think "/var/www/html" is your basic publishing directory AKA DocumentRoot
> and because you're mapping URLs beginning with '/cgi-bin/' into your
> DocumentRoot there are two ways requesting your script:
> http://<your-host>/first.cgi
> and http://<your-host>/cgi-bin/first.cgi


Max,

Thanks it worked. Placing cgi-bin before the script name did the
trick.

Thanks once again.

nagrik



>
> Using the second one should execute your script, but _please_ read about
> the security issues mentioned in
> http://httpd.apache.org/docs/2.0/mo...tml#scriptalias .
>
> .max


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com