Solved

Apache + Perl scripts

Posted on 2000-04-27
16
586 Views
Last Modified: 2010-04-20
I'am new in Linux.
I install RedHat 6.0 and Apache 1.3.9
I have some HTML pages wich invoque Perl Scripts.

So I put in the cgi-bin directory the Perl Scripts and I try to make them work from Apache.
I couldn't....

I would like to know what do I have to change in the httpd.conf so I can execute perl scripts.
And also all that I have to know about this...

I need a good explanation, because I'am new with this.
Remember is Apache 1.3.9...

I've just try this:

If I execute the perl script without Apache: "./test.pl"
says it can't find test.pl

Inside the perl file I have #!/usr/bin/perl

If I execute like this: "perl test.pl" things work fine...


0
Comment
Question by:Pampa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 2
  • +2
16 Comments
 
LVL 40

Expert Comment

by:jlevie
ID: 2757105
Is "test.pl" executable? If it isn't then "./test.pl" won't work. Fix by "chmod ugo+x test.pl". To enable the execution of cgi's you need to modify the cgi-bin definition in httpd.conf to include "options ExecCGI", like:

<Directory "/opt/Apache/cgi-bin">
  AllowOverride None
  Options ExecCGI
  Order allow,deny
  Allow from all
</Directory>
0
 
LVL 40

Expert Comment

by:jlevie
ID: 2757108
Oh yeah, the actual location of the cgi-bin directory will undoubtedly different for your system.
0
 
LVL 4

Expert Comment

by:kiffney
ID: 2757123
make test.pl executable, if it's not already

chmod 0755 test.pl

will probably do it.  
check access.conf (probably in /etc/httpd/conf) and make sure there's an entry

<Directory /home/httpd/cgi-bin>
Options ExecCGI
</Directory>
and restart httpd.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 1

Author Comment

by:Pampa
ID: 2759624
I try the change syou suggest but I still kave the same problem.

I send you the error log of the APache

PD: Prueba.pl is executable but stills says it can-t find the path, I do this outside Apache.... (./Prueba.pl), the same messages appears in the Apache log (see below)

LOG

[error 2] No such file or directory: Exec of /home/Apache/cgi-bin/Prueba.pl failed

[error client 10.0.65.75] Premature end of scripts headers: /home/Apache/cgi-bin/Prueba.pl
0
 
LVL 15

Expert Comment

by:samri
ID: 2760028
Papma,

Where is you perl resides?  try "which perl".

Normall it should resides in /usr/bin, but sometimes, /usr/local/bin

verify it.  and adjust you script accordingly.

0
 
LVL 40

Expert Comment

by:jlevie
ID: 2760060
When you attempt the execution of the perl script via "./Prueba.pl" are you in the /home/Apache/cgi-bin directory? When it fails there (with Prueba.pl at least permissions of rwxr-xr-x) does it say that it can't find Prueba.pl or does it say "Preuba.pl: No such file or directory"? The latter would mean that it can't find /usr/bin/perl. Is there a /usr/bin/perl? Could it be in a different location? Try "which perl" to see where the executable is.

If perl isn't in /usr/bin, you can make a logical link from where it is to /usr/bin. For example it the perl executable is in /usr/local/bin you could do (as root):

ln -s /usr/local/bin/perl /usr/bin/perl
0
 
LVL 1

Author Comment

by:Pampa
ID: 2760305
The message is "Prueba.pl: No such file or directory"?
I follow all your suggestions.

Perl reside in /usr/bin, so I don't need to make a link.

Prueba.pl is executable...

It 's very strange....
Any other idea?

0
 
LVL 4

Expert Comment

by:kiffney
ID: 2760402
Post the output of

stat Prueba.pl

just to make sure you've really set this to be executable.
0
 
LVL 40

Expert Comment

by:jlevie
ID: 2760762
There's either something wrong with the magic token on the first line of Prueba.pl or there's something wrong with what /usr/bin/perl is.

If you do "which perl" what do you see?

Carefuly paste the following two lines into a file that's opened in a Linux editor. Make very sure that the first line of the file is the "#!" token and that there is no leading whitespace on that line.

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

Make the file executable, then try running it with "./some-file".
0
 
LVL 2

Expert Comment

by:ksemat
ID: 2766038
make sure the perl module is loaded in httpd.conf there should be a line LoadModule perl_module /usr/lib/apache/libperl.so
also in it should also be mentioned in AddModule mod_perl.c
Aslo try adding
<Location /cgi-bin>
AddHandler perl-script .pl
PerlHandler Apache::Registry
PerlSendHeader On
Options +ExecCGI
</Location>
if this doesn't work go to http://www.apache.org/docs and lookup documents regarding perl.
0
 
LVL 40

Expert Comment

by:jlevie
ID: 2766383
No you don't need the perl module to be able to execute a perl script as a CGI. The perl script has to be able to be run as if it's a program and that's where his problem lies.
0
 
LVL 1

Author Comment

by:Pampa
ID: 2770078
jlevie:
I try your solution: make a test.pl, then chmod 0755 test.pl

the code of test.pl is:
#!/usr/bin/perl
print "Hello world\n";


Then ./Test.pl in the cgi-bin directory,and I have the same error
"Test.pl: No such file or directory"?
 
If I do perl test.pl works fine.

I belive Perl couldn't be the problem because "Perl filename" won't work.

So colud be a bash probem?

Any other ideas?
Thanks.
0
 
LVL 1

Author Comment

by:Pampa
ID: 2776716
I will give the poinbts to jlevie which was "near" of the final answer.

The solution:
I edit the Perl file with Vi editor which add a <ctrl M> after the #!/usr/bin/perl
So if I edit the perl file with another editor I remove this character and all works fine.
Thanks all, for your comments.
Jlevie please lock the question.
 
0
 
LVL 40

Accepted Solution

by:
jlevie earned 100 total points
ID: 2776820
Okay, but out of curosity... Were you using vi on Linux or on windows to edit the files? I've never see a Linux or Unix vi insert carriage return into a file.
0
 
LVL 1

Author Comment

by:Pampa
ID: 2776956
I import the file from Windows, then I add the line #!.... with the VI of Linux RedHat 6.0

 
0
 
LVL 40

Expert Comment

by:jlevie
ID: 2779522
Ah, that's why. I think in a case like that vi may be "respecting" the line terminators in the file. If you do the transfers with FTP, using "text" mode should cause the carriage returns to be stripped. And you want them to be gone as other Unix things are likely to be confused by their presence.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question