Help using cgi
Hi Di,
Yesterday i tried a "Hello world" program in perl using cgi script on a windows platform. The steps i followed were:
1. Made a directory in "C:" and named it "cgi-bin"
2. Wrote my source code file and saved it with "test.cgi"
############################################################ #################
Source code-
#!/usr/bin/perl
print "Content-type:text/html\r\n\r\n";
print '<html>';
print '<head>';
print '<title>Hello Word - First CGI Program</title>';
print '</head>';
print '<body>';
print '<h2>Hello Word! This is my first CGI program</h2>';
print '</body>';
print '</html>';
1;
############################################################ ##################
3. opened it with my web browser.
but now instead of giving the output it just shows the original source code.
please help!
regards
PS: software that I've installed on my pc is "Strawberry perl plus padre"
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Help using cgi
Hello Prashant,
> Yesterday i tried a "Hello world" program in perl using cgi script
> on a windows platform.
Check out the CGI module on CPAN.
> 3. opened it with my web browser.
>
> but now instead of giving the output it just shows the original
> source code. please help! regards
You have to configure your web server to execute CGI scripts.
Regards,
Alan Haggai Alavi.
--
The difference makes the difference
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Help using cgi
On 11/04/2011 12:05, prashant kaushal wrote:
> Hi Di,
>
> Yesterday i tried a "Hello world" program in perl using cgi script on a windows platform. The steps i followed were:
>
> 1. Made a directory in "C:" and named it "cgi-bin"
> 2. Wrote my source code file and saved it with "test.cgi"
>
> ############################################################ #################
> Source code-
>
>
> print "Content-type:text/html\r\n\r\n";
> print '<html>';
> print '<head>';
> print '<title>Hello Word - First CGI Program</title>';
> print '</head>';
> print '<body>';
> print '<h2>Hello Word! This is my first CGI program</h2>';
> print '</body>';
> print '</html>';
>
> 1;
> ############################################################ ##################
>
> 3. opened it with my web browser.
>
> but now instead of giving the output it just shows the original source code.
> please help!
> regards
>
> PS: software that I've installed on my pc is "Strawberry perl plus padre"
Fist of all, either change the line
#!/usr/bin/perl
to reflect the true path to the perl compiler on your machine. Either
that or change the file type to .pl and make the association with the
compiler.
Secondly, you don't need to print "\r\n" as line terminators. This will
only do what you want if you 'binmode' the output stream; otherwise "\n"
will be output as CR LF, and adding a preceding "\r" will produce CR CR
LF, which doesn't comply with HTTP standards.
Now, you are opening a Perl program file in a web browser. The browser's
job is to interpret what it receives (whether from a local file or a
remote HTTP server) and present it on screen. It expects HTML data (or
perhaps XML) and does its best with any other content by presenting the
data just as it is. There is never any possibility that the browser
should know to /execute/ a Perl program if it sees one; indeed any CGI
code must be run on the server so that it has access to the server's
environment: files, databases etc.
So it is the server's job to run your Perl program and pass its output
to the browser for display. But you have no web server - all you have is
a file, so the browser displays the data from that file.
You must install and configure an HTTP server. The configuration will
determine whether the contents of a given file should be served
unmodified, or be run as a program and the output delivered instead. It
is quite possible to run a server process on the same machine as where
the file and web browser exist, but expect to do a lot of reading to
understand the details of the configuration.
On Windows you should install the 'World Wide Web Services' features.
Unfortunately this is not the forum to help you further with that.
I hope this helps you.
Rob
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Help using cgi
Thanx alan..
please suggest the steps to configure my web server.
regards
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Help using cgi
Hello Prashant,
> Thanx alan..
You are welcome.
> please suggest the steps to configure my web server.
It depends on which web server you are using. You will probably find a
cgi-bin directory (in Debian/Ubuntu, Apache's cgi-bin is at
/usr/lib/cgi-bin/) which is configured to serve CGI scripts. Else, you
will have to configure the web server to allow another directory to
serve CGI scripts and copy the script there.
Regards,
Alan Haggai Alavi.
--
The difference makes the difference
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Help using cgi
--000e0cd32edc74de3b04a0cfa9ec
Content-Type: text/plain; charset=UTF-8
If you are using a Windows System, you can go into the Control Panel, click
"Enable or Disable Windows Components" and select IIS. Depending on
your version of Windows, you should either have IIS 6 / 7, probably IIS7 if
you are using Windows 7 as well. After selecting it, let Windows Install it,
then reboot your computer, use this (http://goo.gl/Ale0z) to download and
set up Perl on IIS. Bind the webserver to your internal IP address, because
so far you probably do not need a publicly available website. Then, put the
*.cgi / *.pl file in your website root, usually C:\inetpub\wwwroot\, and
access it with your browser. It took me a few days of tinkering to get it up
and working properly, but this should suffice for now.
Otherwise, you can download Apache webserver, which comes with perl,
but the instructions for setting that up is different depending on your OS.
(http://httpd.apache.org/, http://perl.apache.org/)
On Tue, Apr 12, 2011 at 2:12 AM, prashant kaushal <p.kaushal07 [at] gmail.com>wrote:
> Thanx alan..
> please suggest the steps to configure my web server.
>
> regards
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
> For additional commands, e-mail: beginners-help [at] perl.org
> http://learn.perl.org/
>
>
>
--
Abizer Lokhandwala
--000e0cd32edc74de3b04a0cfa9ec--