Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Running CGI scripts without a server

by Evanovich (Scribe)
on Apr 02, 2003 at 04:59 UTC ( #247414=perlquestion: print w/replies, xml ) Need Help??

Evanovich has asked for the wisdom of the Perl Monks concerning the following question:

Hello. I have a simple question (which I hope has a simple answer). Can you run a CGI script without going through a web server? I'm waiting on getting access to a website, but I want to begin coding my cgi and editing it, but when I try to run it on my browser (modzilla) I just get the actual text of the code, not the executed file.

Replies are listed 'Best First'.
Re: Running CGI scripts without a server
by thezip (Vicar) on Apr 02, 2003 at 05:46 UTC

    Why not just run a webserver on your PC?

    Apache is a dandy one that runs on virtually every platform...

    Where do you want *them* to go today?
      Well, I installed the Apache package, but I'm not really sure how to use it without giving it a security certificate and all that. I know so little about servers, so there's probably something I'm missing. If someone can steer me towards a good Apache tutorial, I'd certainly be appreciative.

        You won't need a cert.

        Everything you'll need to configure is in httpd.conf. I run Windows 98, so mine is in "C:\Program Files\Apache Group\Apache\conf\httpd.conf".

        There are excellent docs with the Apache package, but I've always thought httpd.conf is very straight-forward. Just make a backup of it in case you screw something up.

        You could also just use the default directories --

        • C:\Program Files\Apache Group\Apache\htdocs
        • C:\Program Files\Apache Group\Apache\cgi-bin

        You'll need to put your scripts in the cgi-bin directory...

        Where do you want *them* to go today?
Re: Running CGI scripts without a server
by PodMaster (Abbot) on Apr 02, 2003 at 05:44 UTC
    Yeah, sure, here's an example from my harddrive
    E:\dev\LOOSE>perl pod.wiki.cgi Title: index Content-Type: text/html; charset=ISO-8859-1 <html><head><title>index</title></head><body><table width='100%'><tr>< +td><table width='100%'><tr><td align='left'><a href='/pod.wiki.cgi/di +s play/AllNodes'>AllNodes</a></td><td align='center'>CGI::Wiki::Simple W +iki</td><td align='right'><form method=post action='/pod.wiki.cgi'><i +n put type='text' name='node' /><input type='hidden' name='action' value +='display' /><input type='submit' value='go' /></form></td></tr></tab +l e>index</td></tr></table><hr /><p>Welcome to a CGI::Wiki::Simple wiki. +</p> <p>The current formatter is <b>CGI::Wiki::Formatter::Default</b></p> <p>There are no <em>implicit</em> links,only <strong>explicit</strong> + ones (as in <TT>&#91;<a href="/pod.wiki.cgi/display/link%20text">lin +k text</a>&#93;</TT> or <TT>&#91;<a href="/pod.wiki.cgi/display/link">t +itle</a>&#93;</TT>)</p> <p>Newlines are taken litelarlly (all lines are wrapped in like <em>&l +t;p&gt;this&lt;/p&gt;</em>).</p> <p>Two single quotes make enclosed text italicized like <em>&quot; thi +s &quot;</em> (you can safely say Rock'n'Roll)</p> <p>Dis&lt;boy&gt;allowed&lt;/boy&gt; html &lt;SCRIPT&gt;disallowed htm +l&lt;/script&gt; &lt;boy&gt;&lt;girl&gt;&lt;/boy&gt;&lt;/girl&gt;</p> <p><pre>Pre tags are allowed</pre></p> <hr /><a href='/pod.wiki.cgi/preview/index'>edit</a> <center> <form method=post action='http://dev.localhost/LOOSE/pod.wiki.cgi'> <a href='http://dev.localhost/LOOSE/pod.wiki.cgi/display/index'>home</ +a> | Powered by <a href='http://search.cpan.org/search?mode=module&query= +CGI::Wiki'>CGI::Wiki</a>::<a href='http://www.corion.net/cgi-bin/wiki +. cgi/display/CGI%3A%3AWiki%3A%3ASimple'>Simple</a> | <input type='text' name='node' /> <input type='hidden' name='action' value='display' /> <input type='submit' value='go' /> </form> </center> E:\dev\LOOSE>
    See, it runs just fine. Web browsers only speak HTTP (you know what I mean) and that means you need a web server your browser can talk to, which in turn executes the CGI scripts for you. Apache is very nice, and there is always HTTP::Daemon (there is also chromatics Jellybean).


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
    ** The Third rule of perl club is a statement of fact: pod is sexy.

Re: Running CGI scripts without a server
by zby (Vicar) on Apr 02, 2003 at 07:50 UTC
Re: Running CGI scripts without a server
by CountZero (Bishop) on Apr 02, 2003 at 15:23 UTC

    If you remember that your "CGI script" is just another fancy word for a Perl program, you will understand that you can just execute your Perl program (either on the command line or through a dedicated editor (Komodo springs to mind as it has a special feature to allow easy feeding of your script with CGI parameters) and see its output. If the output if HTML, some editors can capture it and render it as a browser would do (again (Komodo is able to do so).

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Running CGI scripts without a server
by thoglette (Scribe) on Apr 02, 2003 at 23:22 UTC
Re: Running CGI scripts without a server
by iburrell (Chaplain) on Apr 03, 2003 at 17:42 UTC
    Other people suggested setting up a local web server. This is probably the best way to develop CGI scripts because it mimics how it will run on a real web site. You won't be surprised by differences between development and production environments when you deploy it.

    It is possible to run CGI scripts from the command line. This is very useful for a quick test. You can capture the output, and display the HTML file in a browser. Doing this for multiple pages or interaction will be a really slow process. And there are some things like cookies that won't work right. For example, the HTTP headers will show up at the top of the page unless you remove them in an editor.

    perl script.cgi > script.html
Re: Running CGI scripts without a server
by Anonymous Monk on Apr 03, 2003 at 21:19 UTC
    Download xitami from http://www.xitami.com and run it locally - it works like a dream.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://247414]
Approved by thezip
Front-paged by Trimbach
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2021-01-24 12:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?