Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

running cgi scripts locally

by Angharad (Pilgrim)
on May 24, 2005 at 11:03 UTC ( [id://459882]=perlquestion: print w/replies, xml ) Need Help??

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

Hi again.
I am currently trying to create simple cgi scripts that takes the input from a form and creates some graphics as output.
I have my scripts but is there any way I can run the CGI script locally in a browser without having to resort to uploading it to a server at the moment (seeing as I dont have one right now that might be a bit problematic).
Thanks

Replies are listed 'Best First'.
Re: running cgi scripts locally
by chas (Priest) on May 24, 2005 at 11:47 UTC
Re: running cgi scripts locally
by gwhite (Friar) on May 24, 2005 at 11:10 UTC

    You didn't tell us what kind of system you are running or the OS, but put Perl and a web server on your local machine or network.

    g_White
Re: running cgi scripts locally
by blazar (Canon) on May 24, 2005 at 11:06 UTC
    This comes out often. I have not much experience in these issues, though one answer that I found to be interesting once, was about lynx (or was it links or elinks or...?) which should have exactly the kind of feature you're after. I don't have the slightest idea wether this could apply to some graphic browser as well.
Re: running cgi scripts locally
by rlucas (Scribe) on May 24, 2005 at 13:24 UTC
    If you have relatively simple CGI scripts on Windows, a tool called "OptiPerl" from Xarka has most of an IDE, plus a mini-webserver that allows you to view the outputs as web pages. I haven't been down the road of reevaluating *nix Perl IDEs lately (although I imagine there are some good plugins for NetBeans and Eclipse by now; I've been sticking to the "Unix IS the IDE" mentality), but I know from working with NetBeans and Eclipse for Java that they do offer something similar.

    Once you start getting complicated enough, it makes sense to just to write a script to set up your development environment and require that Apache (or whatever) be a part of that.

    Something we often do for testing is set up a single-instance webserver on a nonprivileged port; this is generally enough for day to day, and as long as it's actually CGI and not mod_perl or similar, you can use a very low key webserver. Of course, there's nothing like testing in the exact environment in which you anticipate deployment.

Re: running cgi scripts locally
by Angharad (Pilgrim) on May 24, 2005 at 14:00 UTC
    Thanks everyone for the help so far. I installed apache2 on suse 9.1. I modified the conf script and ensured that the permissions on /srv/www/htdocs were ok but although I can read the test page for Apache I cant get to read the index.html page. It says
    Access forbidden!
    You don't have permission to access the requested object. It is either read-protected or not readable by the server
    I know this isnt a perl question, but thought I would ask anyway, if anyone has any suggestion as to how to sort this out because it is driving me nuts!
      but although I can read the test page for Apache I cant get to read the index.html page

      Which index.html? If you can read the test page for apache, which is probably /srv/www/htdocs/index.html, I'm assuming you mean the index.html in your ~/public_html? If so, make sure your toplevel home directory , like /home/Angharad is at least mode 711, so the server can descend into your home dir. Remember, that apache will run as (nobody,nogroup) or some other lowest possible permissions, unless suexec is enabled, then it will run as (user,group) in the public_html directories.


      I'm not really a human, but I play one on earth. flash japh
Re: running cgi scripts locally
by Angharad (Pilgrim) on May 24, 2005 at 11:14 UTC
    Well, I'm running Suse 9.1 at the moment. And perl is of course already installed. So, I have to install a web server on my local machine before I can test these scripts out?
    Gulp. How do I do that?
      Installing apache on suse is quite easy if you use the apache rpms that come with it. The only tricky part (if you've never done that) is probably going to be configuring apache in such a way that you can easily write & run cgi scripts from your development directory (probably in your homedir).

      I've got the following entry in my (apache 1.3) configuration:

      # # UserDir: The name of the directory which is appended onto a user's h +ome # directory if a ~user request is received. # <IfModule mod_userdir.c> UserDir public_html # # Control access to UserDir directories. The following is an example # for a site where these directories are restricted to read-only. # <Directory /home/*/public_html> AllowOverride All AddHandler perl-script .cgi Options All +ExecCGI <Limit GET POST OPTIONS PROPFIND> Order allow,deny Allow from all </Limit> <Limit PUT DELETE PATCH PROPPATCH MKCOL COPY MOVE LOCK UNLOCK> Order deny,allow Deny from all </Limit> </Directory> </IfModule>

      Which means that every user's "public_html" directory in their homedir is accessible as http://localhost/~username/ and that files ending in .cgi will be run as cgi scripts.

      In all probability you already have apache installed on the machine, if not you should be able to install the appropriate package from the installation medium using YaST or whatever SuSE use as a package manager these days.

      /J\

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://459882]
Approved by blazar
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-23 21:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found