Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot run any perl scripts using ActiveState Perl

Status
Not open for further replies.

dps

Programmer
Feb 2, 2001
157
GB
Hello,

I am fairly new to perl.

I have initiated following the book - "Perl in easy steps".

Have installed the Apache http server 2.0.50 and also v5.8.4 built for MSWin32-x86-multi-thread.

My OS is Windows XP Prof. version 5.1 SP2.

When my installation completes I do get the apache web server started and get the default Apache
front page when entering url
My perl is set up D:\usr\Perl (D local disk file system=NTFS)

Problem is when trying to run a perl script (eg hello.pl) by entering but get "The page cannot be found...." "HTTP 404 - File not found
Internet Explorer"

I have checked the httpd.conf file, scoured the web and Tek Tips but cannot explain why any of the .pl scripts
cannot run - am I missing something simple?

How can I go round diagnosing the problem. I really want to kick into learning Perl but this is hindering me. Cannot spend too much time searching any more for a resolution. Can anyone help???
 
You can debug your perl scripts using a standard windows DOS Prompt...i.e. go to Start -> Run -> type in 'command'.

When running perl files from command prompt, you have to put in 'perl' followed by the entire path to the file. Unless at the begining of your hello.pl you have the line '#!c:/perl/bin/perl.exe' this automatically tells windows it's a perl file you are trying to run and what program to use to open it.

Apache web server usually creates a folder in C:/Program files/Apache/Apache2/htdocs/ or something along those lines, which is where you should be saving your hello.pl file to, it shouldn't actually matter whether you put them in a cgi_bin or not.

Make sure your paths/directories etc are right...I'm sure you've already done that. In order to get perl/cgi files to run through an apache server there are also a few lines in the httpd.conf file that will need changing or adding to. It's been a while since I used Apache so you may have to investigate this yourself, unless some other kind soul will show you!

A 404 error points to the fact that your hello.pl file isn't where you think it is or where Apache thinks it should be. If it was there then you would probably get a different error saying there was a problem with your script.

Rob Waite
 
when I start up my DOS, the first directory on the prompt is D:\Documents and Settings\DPS which is my profile. From here I can type perl hello.pl and get " Can't open perl script "hello.pl": No such file or directory" . When I navigate to "D:\Program Files\Apache Group\Apache2\cgi-bin"
....and do....
>perl hello.pl
Hello World

I have the hello.pl in the D:\Program Files\Apache Group\Apache2\cgi-bin, despite this I get the error. Maybe something to do with path settings?

In my httpd.conf I have following -

DocumentRoot "D:/Program Files/Apache Group/Apache2/htdocs
further down .....
<Directory "D:/Program Files/Apache Group/Apache2/htdocs">

ScriptAlias /cgi-bin/ "D:/Program Files/Apache Group/Apache2/cgi-bin/"

Do I need to have some CPAN modules installed or am I deviating?
 
right, if you run a perl program in the dos prompt, Apache doesn't even come into it.

What error do you get when you've navigated to the directory where hello.pl exists?

Maybe copy and paste the error here with the script from your program so that I can see if your code is correct?

Rob Waite
 
Waiterm - when I navigate to the directory where hello.pl exists (i.e. D:/Program Files/Apache Group/Apache2/htdocs) and run it in DOS it works - prints hello world.....
 
dps - in your first message at the top you say you went to this address:
Make sure it is a dash and not underscore - should be
Also - if you want to run your perl scripts from anywhere in dos, add it to your path.
I believe the command is:
path D:\Program Files\Apache Group\Apache2\cgi-bin; %path%
 
Thanks for that oversight Brian atwork with that I get a resulting

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, dps@ntlworld.com 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

I shall check the log file.

Thanks!!
 
In the hello.pl I have #!D:\usr\Perl\bin

Still when this is run I get following in error log

Tue Oct 12 18:42:13 2004] [error] [client 127.0.0.1] (OS 3)The system cannot find the path specified. : couldn't spawn child process: D:/Program Files/Apache Group/Apache2/cgi-bin/hello.pl

and also 127.0.0.1 - - [12/Oct/2004:18:50:41 +0100] "GET /cgi-bin/hello.pl HTTP/1.1" 500 616

in the access.log

Any suggestions - as not getting anywhere with Google?
 
Brian my path already has D:\Program Files\Apache Group\Apache2\cgi-bin
 
dps the file has to reside in the cgi-bin directory, where the path is specified

based on your configuration means the file should be located at
D:/Program Files/Apache Group/Apache2/cgi-bin/hello.pl

and not

Tue Oct 12 18:42:13 2004] [error] [client 127.0.0.1] (OS 3)The system cannot find the path specified. : couldn't spawn child process: D:/Program Files/Apache Group/Apache2/cgi-bin/hello.pl

Also Apache is fairly picky about headers

for hello.pl consider the following
Code:
#!D:/usr/bin/perl/bin
use CGI;
$q = new CGI;
print $q->header;
print $q->start_html(-title=>"Dps' hello world sample");
print $q->"Hello World\n";
print $q->end_html();

HTH
--Paul



It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ... smack the fecker
 
Hey DPS - One more thing:
When debugging, I put this right under my #!/usr/bin/perl line:
Code:
use CGI::Carp 'fatalsToBrowser';
This is often much more specific and helpful than the Internal Server Error 500 that we all grow to hate. If you do not have the CGI modules, it would be good to install them from CPAN - they make your life easier.

Just try putting that line at the top of your script - if you have the CGI module and you get an error, it usually echos the error output from perl straight to your webpage!
 
how'd you do it?
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ... smack the fecker
 
Thanks for the info Paul TEG; I did mention that in my httpd.conf I had enabled my ScriptAlias /cgi-bin/ "D:/Program Files/Apache Group/Apache2/cgi-bin/"


The way I got it to work is as follows:

Closed my bowser from where I previously left off

Placed an extra line in the hello.pl - print "Content-type:text/html\n\n";

In the url address I entered -
Hit the return key and hey PRESTO!

renaming the hello.pl to hello.cgi and running thast as also worked with the addition of that one line.


Thanks Brian for that - ps. How do I install the various modules from CPAN. Have not reached that far into Perl yet. Having said that I need to query Oracle from Perl.
 
Use the Perl Package manager

ppm install whatever

For using CPAN, have a look at the FAQ section here

HTH
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ... smack the fecker
 
you can also search for modules on PPM through the DOS prompt using 'ppm s [part of module name]' this will give you a list, then you can use 'ppm i [full module name]' to install it.

If I remember correctly you can also set up CPAN to run in a similar way, if in the DOS prompt you type in CPAN then it should install CPAN for you...'install Bundle::CPAN' comes into it somewhere.

A moajority of modules you just have to put the *.pm file into the /perl/lib/ directory, which is wherever your installation of perl looks for modules. Or you can create your own lib using:
Code:
use lib c:/path/directory/blah/


Rob Waite
 
Thanks for that. If I enter CPAN at DOS prompt it prompts for manual or automatic install - which is advisable?
 
probably in your case I would suggest automatic, unless you are confident that you can answer its questions correctly. If I remember correctly it asks for basic information such as directories and paths, and then more complicated stuff which involves whether you have nmake, gzip, cl, etc installed. Most of these are normal on UNIX systems but I found them to be a pain in the backside on my Windows setup. I would suggest if you're fairly new to Perl, if you can't find it in PPM then don't use it, use CPAN as a last resort!!

Rob Waite
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top