Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

setting up a localhost

by Anonymous Monk
on Mar 11, 2004 at 04:38 UTC ( #335704=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I recently downloaded both perl and apache to my windows box. Looks like both installed just fine. The only problem I have is that I don't know how to set up the localhost portion of the URL for running CGI/perl scripts.

For Example: http://localhost/cgi-bin/test.cgi

how do I configure the localhost portion of the URL? I'm not sure whether to put the name of my computer there, or to create my own ip or subnetmask or something like that. I'm pretty unfamiliar with this. Any suggestions?

Comment on setting up a localhost
Re: setting up a localhost
by bart (Canon) on Mar 11, 2004 at 05:09 UTC
    You should be able to find a "hosts" file in the Windows directory (or whatever its name is on your flavour of Windows), without any file extension. It's a pure text file, the Windows equivalent of the /etc/hosts file on Unix. In it, you can define any name you want for your local systems, even morethan one, there's no need to set up a DNS system. The file should exist, and it should contain some sample entries, perhaps commented out, giving you a good idea what the systax to use is. And one of these entries should be for "localhost"...
Re: setting up a localhost
by saintmike (Vicar) on Mar 11, 2004 at 05:19 UTC
    You didn't mention which version of Apache, I'm assuming 1.3.29 (Apache 2.0 should be similar, though). Now, if you go to either
    http://localhost
    or
    http://127.0.0.1
    with your browser, you should see the apache test page. If that's showing, Apache was installed correctly.

    Now for the cgi-bin part: Make sure that your apache installation has a cgi-bin directory and the script you're calling is in there. Depending on your installation, this might be in C:\Program Files\Apache Group\Apache\cgi-bin or similar.

    Then, open a DOS (gack!) window, go into the directory and try running the script by hand:

    perl test.cgi
    Check the output. If that shows something like

    Content-type: text/plain CGI/1.0 test script report: ...
    then you're in business and can try
    http://localhost/cgi-bin/test.cgi
    in your browser. Let us know at which part of the way you're stuck, and we can provide more help.
      Thank you for your help. I tested the script out on the command line and it worked.
      However, I am still having trouble with the localhost thing.
      The following is the code I'm trying to execute:
      #!C:\perl\bin\perl.exe -w use strict; use CGI; my $query = new CGI; print $query->header( "text/html" ); print <<END_HERE; <html> <head> <title>My First CGI Script</title> </head> <body bgcolor="#FFFFCC"> <h1>This is a pretty lame Web page</h1> <p>Who is this Ovid guy, anyway?</p> </body> </html> END_HERE # must have a line after "END_HERE" or Perl won't recognize # the token
      Running that code on the command line produces the following result which seems to have no errors:
      C:\Program Files\Apache Group\Apache2\cgi-bin>perl test.cgi Content-Type: text/html; charset=ISO-8859-1 <html> <head> <title>My First CGI Script</title> </head> <body bgcolor="#FFFFCC"> <h1>This is a pretty lame Web page</h1> <p>Who is this Ovid guy, anyway?</p> </body> </html>
      The Problem I am having is that I can't even get the apache test page to load when I type http://127.0.0.1 in for the URL.
      I set up my httpd.conf file like the following:
      # ServerName gives the name and port that the server uses to identify +itself. # This can often be determined automatically, but we recommend you spe +cify # it explicitly to prevent problems during startup. # # If this is not set to valid DNS name for your host, server-generated # redirections will not work. See also the UseCanonicalName directive +. # # If your host doesn't have a registered DNS name, enter its IP addres +s here. # You will have to access it by its address anyway, and this will make + # redirections work in a sensible way. # # 127.0.0.1:80 This didn't work # localhost This also didn't work for me. # ServerName 127.0.0.1
      I'm running apache 2.0.48
      when I type, http://127.0.0.1/cgi-bin/test.cgi
      the browser just continuously tries to load the page like an endless loop. nothing happens.
      when I type, http://127.0.0.1
      nothing happens. I don't even get the apache test page. do you think that ZoneAlarm will cause a problem with this? I'm also running a router so that a couple of computers in the house can have access to the internet. maybe that is causing the problem. I can't see why that would be causing a problem because I'm not trying to access the internet when I'm running this perl script/cgi stuff. I'm just trying to view the scripts on my own computer.
Re: setting up a localhost
by AcidHawk (Vicar) on Mar 11, 2004 at 07:11 UTC
    In the httpd.conf file there is this explination
    # ServerName allows you to set a host name which is sent back to clien +ts for # your server if it's different than the one the program would get (i. +e., use # "www" instead of the host's real name). # # Note: You cannot just invent host names and hope they work. The name + you # define here must be a valid DNS name for your host. If you don't und +erstand # this, ask your network administrator. # If your host doesn't have a registered DNS name, enter its IP addres +s here. # You will have to access it by its address (e.g., http://123.45.67.89 +/) # anyway, and this will make redirections work in a sensible way. # # 127.0.0.1 is the TCP/IP local loop-back address, often named localho +st. Your # machine always knows itself by this address. If you use Apache stric +tly for # local testing and development, you may use 127.0.0.1 as the server n +ame. # ServerName myservername
    This will allow me to call http://localhost or http://myservername in the URL

    In the same file you also need to make sure that your cgi-bin settings are correct..

    # ScriptAlias: This controls which directories contain server scri +pts. # ScriptAliases are essentially the same as Aliases, except that # documents in the realname directory are treated as applications +and # run by the server when requested rather than as documents sent t +o the client. # The same rules about trailing "/" apply to ScriptAlias directive +s as to # Alias. # ScriptAlias /cgi-bin/ "C:/Documents and Settings/Administrator/My +Documents/myweb/cgi-bin/" # # "C:/Program Files/Apache Group/Apache/cgi-bin" should be changed + to whatever your ScriptAliased # CGI directory exists, if you have that configured. # <Directory "C:/Documents and Settings/Administrator/My Documents/m +yweb/cgi-bin"> AllowOverride None Options None Order allow,deny Allow from all </Directory>
    Your cgi script shoud go in this dir. On the windows platform make sure you have the #!perl.exe line as the first line of your script, and that perl.exe is in your path.

    -----
    Of all the things I've lost in my life, its my mind I miss the most.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (13)
As of 2014-10-20 12:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (75 votes), past polls