Solved

Apache + Perl scripts

Posted on 2000-04-27
16
581 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
  • 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
 
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
docker invalid registry name 2 107
Problem to start Neon 20 89
Removing DES and 3DES ciphers in linux RedHat 6.8 38 100
Linux/Apache File Ownership/Permissions 1 54
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
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 get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now