?
Solved

Apache + Perl scripts

Posted on 2000-04-27
16
Medium Priority
?
590 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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 300 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

770 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