Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

CGI-bn on Apache on Windows Xp

Options
  • 23-08-2004 9:29pm
    #1
    Closed Accounts Posts: 1,541 ✭✭✭


    HI.

    I have got my Apache server running on XP. I want to be able to use the CGI-bin to test PERL scripts.

    (1) How do I configure/allow access to the CGI-bin? I can't find reliable info on this on the internet

    (2) What do I need to run my PERL scripts? I have seen ActivePERL on the net. Do I download it? Where do I put it? If I write a PERL program in notepad how do I go about putting/testing it in the CGI bin?

    Thanks for any advice. :)


Comments

  • Closed Accounts Posts: 304 ✭✭Zaltais


    It's straight forward enough.

    First install Perl - ActivePerl is probably the easiest to install on Windows, and the most flexible.

    Once you've done that you just need to modify your Apache config file

    I found this after a quick google, seems to cover all the basics...

    If you've any specific problems, or get stuck after installing Perl, just ask.

    Alternatively you could use one of the preconfigured installers that will install Apache, MySQL, PHP, perl, and mod_perl for you.

    Such as XAMPP which looks to have all that, and the kitchen sink thrown in for good measure..... (nerver used it myself though, so usual disclaimers apply...)


  • Closed Accounts Posts: 1,541 ✭✭✭finnpark


    Thanks Zaltais. I have installed ActivePerl at c:/Perl/bin/Perl.exe :D .

    I think the httpd.conf file is configured correctly like whats in that link.

    When I set up Apache there was allready a CGI-bin there with a PERL script called "printenv.pl" in it. I have got this working I think. When I enter http://localhost/cgi-bin/printenv.pl I het the following:

    COMSPEC="C:\WINDOWS\system32\cmd.exe"
    DOCUMENT_ROOT="C:/Program Files/Apache Group/Apache2/htdocs/"
    GATEWAY_INTERFACE="CGI/1.1"
    HTTP_ACCEPT="text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
    HTTP_ACCEPT_CHARSET="ISO-8859-1,utf-8;q=0.7,*;q=0.7"
    HTTP_ACCEPT_ENCODING="gzip,deflate"
    HTTP_ACCEPT_LANGUAGE="en-us,en;q=0.5"
    HTTP_CONNECTION="keep-alive"
    HTTP_HOST="localhost"
    HTTP_KEEP_ALIVE="300"
    HTTP_USER_AGENT="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3"
    PATH="C:\Perl\bin\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem"
    PATHEXT=".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH"
    QUERY_STRING=""
    REMOTE_ADDR="127.0.0.1"
    REMOTE_PORT="3383"
    REQUEST_METHOD="GET"
    REQUEST_URI="/cgi-bin/printenv.pl"
    SCRIPT_FILENAME="C:/Program Files/Apache Group/Apache2/cgi-bin/printenv.pl"
    SCRIPT_NAME="/cgi-bin/printenv.pl"
    SERVER_ADDR="127.0.0.1"
    SERVER_ADMIN="hidden@hidden.ie"
    SERVER_NAME="localhost"
    SERVER_PORT="80"
    SERVER_PROTOCOL="HTTP/1.1"
    SERVER_SIGNATURE="<address>Apache/2.0.50 (Win32) Server at localhost Port 80</address>\n"
    SERVER_SOFTWARE="Apache/2.0.50 (Win32)"
    SYSTEMROOT="C:\WINDOWS"
    WINDIR="C:\WINDOWS"

    Is this ok?


    However whenever I try to run any example script from ActivePERL or my own "Hello World" program I get the following error when I enter http://localhost/cgi-bin/helloworld.pl :

    Internal Server Error
    The server encountered an internal error or misconfiguration and was unable to complete your request.
    Please contact the server administrator, hidden@hidden.ie and inform them of the time the error occurred, and anything you might have done that may have caused the error.
    More information about this error may be available in the server error log.

    Apache/2.0.50 (Win32) Server at localhost Port 80.


    HELLOWORLD.PL is shown below:

    #!c:/Perl/bin/Perl.exe
    print "Content-type: text/html\n\n";
    print "<h2>Hello, World!</h2>\n";


    I didnt change anything in the httpd.conf file yet but it allready seems to be ok. Also since printenv works I presume its ok. However when I try examples like the above I get an internal server error. Any ideas???
    :confused:

    Thanks :)


  • Closed Accounts Posts: 304 ✭✭Zaltais


    Yeah, your CGI-BIN looks to be configured correctly based on the fact that printenv.pl works ok...

    Have you checked the error log to see what's wrong?

    Your error log should be in C:\Program Files\Apache Group\Apache\logs\error.log
    (assuming you didn't change the default install location)

    Basically, navigate to your helloworld.pl file and then open the error log. Paste the last 10 lines or so of it here if it doesn't seem to make sense...


  • Closed Accounts Posts: 1,541 ✭✭✭finnpark


    I will do that this evening. Yes the printenv.pl works ok.

    "Basically, navigate to your helloworld.pl". How do you mean? Do you just double clivk on it?

    Also one more thing. There is a httpd.conf and a httpd.conf.default....Is this normal? Is there always a default one also.

    I will check the error log and get back to you.

    Thanks :)


  • Closed Accounts Posts: 304 ✭✭Zaltais


    Sorry by 'navigate to your helloworld.pl' I just meant 'go to http://localhost/cgi-bin/helloworld.pl' - nothing more complicated, despite the way it sounds!

    Yeah, it's normal to have httpd.conf.default - it's there so when you break your httpd.conf and everything stops working, you can have a backup of the default settings.


  • Advertisement
  • Closed Accounts Posts: 1,541 ✭✭✭finnpark


    Thanks.

    One other thing. I put the following program in a CGI-bin on Tripod and it would not work. The PERL execution path is right. Where am I going wrong? Does anyone have a PERL program that works for sure and tell me how to modify to work on mine? Here is another PERL not-working program. I tried this one on Tripod:

    #!/usr/bin/perl
    print "Hello, world!\n";


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    You'll need to print out the HTTP header (Content-type etc.) for the one above, not sure what's wrong with the other one.


  • Closed Accounts Posts: 304 ✭✭Zaltais


    That particular one won't work because it doesn't output content headers - in your original post you had a script like so
    #!c:/Perl/bin/Perl.exe
    print "Content-type: text/html\n\n";
    print "<h2>Hello, World!</h2>\n";
    

    the line:
    print "Content-type: text/html\n\n";
    
    is vitally important.

    However, it would also need execute permissions on a *NIX based host - so that could be an additional problem on your Tripod account - this is far far less likely to be a problem on your windows install


  • Closed Accounts Posts: 1,541 ✭✭✭finnpark


    #!/usr/bin/perl
    print "Content-type: text/html\n\n";
    print "<h2>Hello, World!</h2>\n";


    I got the above working on tripod. :D Thanks lads.

    I will try it on my own server at lunchtime and will get back to you with my log errors. :mad: Do I just need to change the first line of this?

    Thanks Again


  • Closed Accounts Posts: 304 ✭✭Zaltais


    Yeah, just the first line...


  • Advertisement
  • Closed Accounts Posts: 1,541 ✭✭✭finnpark


    I should replace the irst line with #!c:/Perl/bin/Perl.exe. Correct me if Im wrong :)


  • Closed Accounts Posts: 1,541 ✭✭✭finnpark


    It is still not working. The hello world program was saved in cgi-bin as second2.pl. This program worked on Tripod. Only the first line was changed. Below is the log errors for it:

    [Tue Aug 24 13:26:21 2004] [error] [client 127.0.0.1] C:/Program Files/Apache Group/Apache2/cgi-bin/second2.pl is not executable; ensure interpreted scripts have "#!" first line

    [Tue Aug 24 13:26:21 2004] [error] [client 127.0.0.1] (9)Bad file descriptor: don't know how to spawn child process: C:/Program Files/Apache Group/Apache2/cgi-bin/second2.pl

    [Tue Aug 24 13:26:23 2004] [error] [client 127.0.0.1] C:/Program Files/Apache Group/Apache2/cgi-bin/second2.pl is not executable; ensure interpreted scripts have "#!" first line

    [Tue Aug 24 13:26:23 2004] [error] [client 127.0.0.1] (9)Bad file descriptor: don't know how to spawn child process: C:/Program Files/Apache Group/Apache2/cgi-bin/second2.pl :confused:


  • Closed Accounts Posts: 304 ✭✭Zaltais


    Have to admit, I've never seen that one before...

    On the upside - what this does mean is that it's trying to execute it, it just can't. Either because it can't find your perl interpreter or because it doesn't work for some reason.

    What I'd suggest first and foremost is that you ensure that Perl.exe is at c:/Perl/bin/Perl.exe - I'm sure it is, but it doesn't hurt to check...

    Then I'd change the shebang line (the first line that starts with #!) to
    #!c:/Perl/bin/Perl

    I'll have to re-install and configure Perl for my cgi-bin on my windows PC, cos it's been a while since I did this on windows, but try the two above and see how you get on...


  • Closed Accounts Posts: 1,541 ✭✭✭finnpark


    Thanks Zaltais. Yes I think I understand the problem. It cannot execute my program eventhough Tripod can. It is probably to do with that first line allright. Even if I copy the printenv.pl to another notepad and save it as somrthing else it still works but my hello world script never works. I will try more tonight.

    Is it possible that I downloaded or installed wrong Active PERL? I will try to re-install it. Also I will re-install apache. It could be another XP problem. XP is a nightmare.

    I am using the same shebang line in my helloworld thats in the printenv.pl. Do I have to give the file special permission or anything? I did also try that other shebang line you reccommended without the .exe extension. I will try it again.

    One other thing. I deleted the apache default page. Do you think this would make a difference? Thanks Again
    :)


  • Closed Accounts Posts: 304 ✭✭Zaltais


    finnpark wrote:
    Thanks Zaltais. Yes I think I understand the problem. It cannot execute my program eventhough Tripod can. It is probably to do with that first line allright. Even if I copy the printenv.pl to another notepad and save it as somrthing else it still works but my hello world script never works. I will try more tonight.

    Odd indeed...
    finnpark wrote:
    Is it possible that I downloaded or installed wrong Active PERL? I will try to re-install it. Also I will re-install apache. It could be another XP problem. XP is a nightmare.

    Unlikely to make a difference - if neither script worked, then perhaps this might solve your problem. But the fact that one works and the other doesn't would lead one to believe that it's a simple (but extremely frustrating) problem.
    finnpark wrote:
    I am using the same shebang line in my helloworld thats in the printenv.pl. Do I have to give the file special permission or anything? I did also try that other shebang line you reccommended without the .exe extension. I will try it again.

    Maybe XP is different, but you shouldn't have to set any special permissions, but just to check - set the helloworld.pl file as executable by 'Everyone'
    finnpark wrote:
    One other thing. I deleted the apache default page. Do you think this would make a difference? Thanks Again
    :)

    Not in the slightest...


  • Closed Accounts Posts: 1,541 ✭✭✭finnpark


    Ok got it working. :D:D:D:D

    I just didn't realise that you can't tab the 1st line over. The shebang line must be fully to the left of the page for it to execute. Did you know this? Im sure everyone knows this apart from me :o .

    Anyway thanks for your help, it owuld have taken me ages to learn this on my own plus a lot of un-nesseccary effort. Also I learned a lot more about what Im doing along the way.

    I must try to write to a file on my C drive and also try to execute a C program on my C dive from the internet.

    Many thanks again. :D


  • Closed Accounts Posts: 304 ✭✭Zaltais


    finnpark wrote:
    Ok got it working. :D:D:D:D

    Hurrah!!
    finnpark wrote:
    I just didn't realise that you can't tab the 1st line over. The shebang line must be fully to the left of the page for it to execute. Did you know this? Im sure everyone knows this apart from me :o .

    Errrm, yeah, unfortunately that was one of those things I kind of took for granted, especially when you got your other script working on Tripod. Ah well, at least you won't forget it in a hurry!

    Glad to hear you got it sorted! :D


Advertisement