Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

local webserver for CGI on linux

by my_nihilist (Sexton)
on Sep 19, 2008 at 16:39 UTC ( #712549=perlquestion: print w/replies, xml ) Need Help??
my_nihilist has asked for the wisdom of the Perl Monks concerning the following question:

Is apache the best option if I want to run a local server for doing CGI, etc., or is there a simpler option?

Better yet, can I write a "TCP" server with UNIX sockets to do this -- and if so where should I start reading?

Replies are listed 'Best First'.
Re: local webserver for CGI on linux
by zentara (Archbishop) on Sep 19, 2008 at 18:02 UTC
    Go with Apache, because that way you will understand the workings of it, which comes in handy when you move to a real server. There are alot of details to consider when running cgi, ranging from https, configuration files, htaccess files, user permissions, etc. Simpler servers just don't handle cgi scripts in full detail.

    Most linux distros will setup Apache for you right out of the box.

    I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: local webserver for CGI on linux
by Illuminatus (Curate) on Sep 19, 2008 at 17:46 UTC
    Better yet, why don't you write your own OS to run for your server :) With all the web servers available (apache, mini_httpd, appWeb, etc, etc, etc), why would you even consider writing your own? What you choose should depend on your requirements. Was there a perl question in there somewhere?
      Was there a perl question in there somewhere?

      By "write" I meant "in perl". Consider it a learning experience. Also, all I need is something that will run scripts from a cgi-bin locally based on a singular, established connection. Having never used apache, I figured that by the time I understand it I could have written something to do this (in perl).

      This is what I have so far based on various examples:
      #!/usr/bin/perl -w use strict; # simple server use Socket; use IO::Handle; socket(SERV, PF_UNIX, SOCK_STREAM,0); unlink "/tmp/testsock"; bind(SERV,sockaddr_un("/tmp/testsock")) or print "ERROR!"; listen(SERV,1); while (accept(CLIENT,SERV)) { CLIENT->autoflush(1); print CLIENT "Hi there!\n"; my $answer = <CLIENT>; print $answer; }
      #!/usr/bin/perl -w use strict; # simple client use Socket; use IO::Handle; socket(TSOCK, PF_UNIX, SOCK_STREAM,0); connect(TSOCK, sockaddr_un("/tmp/testsock")) or print("ERROR!"); while (defined(my $messg = <TSOCK>)) { print $messg; print TSOCK "Hello server!"; TSOCK->flush; }
      This works to the point where the server should recieve and print the answer from the client -- it doesn't. The initial "Hi there!" is recieved and printed tho. Once I can get back and forth communication working, I should be able to figure out what to do next.

      Being kind of a luddite, I preferred not to use IO::Socket for the learning experiment.
        Having never used apache, I figured that by the time I understand it I could have written something to do this (in perl).

        Reading and understanding enough of RFC 2616 (for example) to implement your own web server effectively will take more time than installing and configuring Apache httpd through XAMPP or any decent modern free Unix-like system.

        This is not a web-server. It's just socket communication. Your program probably does not work because there is no linefeed in the "Hello server!". Even though you flushed, your server-side read is looking for the linefeed.

        If your communication is across systems, look at inetd/xinetd. There is plenty of documentation on them, and they are very easy to use.

Re: local webserver for CGI on linux
by blazar (Canon) on Sep 19, 2008 at 18:23 UTC

    Slight expansion on zentara's answer, due to the sloppiness of your question: use the webserver you will be using in a "real environment" if you're planning on using a "real environment" or, to bring the discussion back to Perl, iirc there are several modules offering minimal web servers entirely implemented in Perl itself, one being HTTP::Server::Simple.

    If you can't understand the incipit, then please check the IPB Campaign.
Re: local webserver for CGI on linux
by derby (Abbot) on Sep 19, 2008 at 18:11 UTC

    It really depends on what you want to do (that 'etc' part - very managerial - it's going to burn you) and where/how you want your local server experience to go. So ... I think apache is your best option, followed by lighthttpd and then followed by the myraid of lightweight http servers on cpan.

    And what OS you're using plays a big part too. OS X all ready comes with apache (I think), on windows, xampp is going to be fairly easy to install while most modern linux distros have what, 87 or so different web servers to choose?


    update:doh! didn't see linux in the title ... ubuntu has about a dozen http servers ... I'd stick with apache.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://712549]
Approved by planetscape
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2018-05-25 09:55 GMT
Find Nodes?
    Voting Booth?