Solved

Apache + Perl scripts

Posted on 2000-04-27
16
576 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
Comment Utility
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
Comment Utility
Oh yeah, the actual location of the cgi-bin directory will undoubtedly different for your system.
0
 
LVL 4

Expert Comment

by:kiffney
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Post the output of

stat Prueba.pl

just to make sure you've really set this to be executable.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 40

Expert Comment

by:jlevie
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

6 Experts available now in Live!

Get 1:1 Help Now