problem with perl modules declaration and perl/cgi script
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
problem with perl modules declaration and perl/cgi script
I have Ubuntu 9.10 with Apache 2.2.x and perl 5.10.0.
I writed littles perl modules in my home directory.
I tried to lanch a following perl/cgi:
Quote:
#!/usr/bin/perl
use MyModule;
my $cgi = CGI->new();
my $mProject = new MyModule;
$mProject->create;
I have .html files in /var/www directory and perl/cgi script in /usr/lib/cgi-bin directory but MyModule is in my home directory.
Firefox output 500 Internal Server Error.
/var/log/apache2/error.log file is:
Quote:
[Tue Feb 23 15:28:22 2010] [error] [client ::1] Premature end of script headers: createproj.cgi, referer: http://localhost/projects.html
Can't locate MyModule.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at /usr/lib/cgi-bin/createproj.cgi line 3.
BEGIN failed--compilation aborted at /usr/lib/cgi-bin/createproj.cgi line 3.
[Tue Feb 23 15:39:27 2010] [error] [client ::1] Premature end of script headers: createproj.cgi, referer: http://localhost/projects.html
Can't locate MyModule.pm in @INC (@INC contains: /my/home/dir/ /etc/perl /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at /usr/lib/cgi-bin/createproj.cgi line 4.
BEGIN failed--compilation aborted at /usr/lib/cgi-bin/createproj.cgi line 4.
[Tue Feb 23 16:45:28 2010] [error] [client ::1] Premature end of script headers: createproj.cgi, referer: http://localhost/projects.html
Can't locate MyModule.pm in @INC (@INC contains: /my/home/directory/ /etc/perl /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at /usr/lib/cgi-bin/createproj.cgi line 5.
BEGIN failed--compilation aborted at /usr/lib/cgi-bin/createproj.cgi line 5.
[Tue Feb 23 20:24:22 2010] [error] [client 127.0.0.1] Premature end of script headers: createproj.cgi, referer: http://localhost/projects.html
The /usr/lib/cgi-bin/createproj.cgi script is:
Quote:
#!/usr/bin/perl -w
use strict;
use lib "/my/home/directory/";
use MyModule;
use CGI;
my $cgi = CGI->new();
print $cgi->header();
my $pname = $cgi->param('projname');
print 'pname = '.$pname."\n";
my $mProject = new MyModule;
$mProject->create($pname);
myname@desktop:/home$ ls -lh
totale 4,0K
drwxr-xr-x 54 myname myname 4,0K 2010-02-23 20:24 myname
myname@desktop:/home$
No, excuse me, I mistaked, I didn't solve my problem.
1)
In Firefox appears: 500 Internal Server Error
2)
/var/log/apache2/error.log file is:
Quote:
Can't locate MyModule.pm in @INC (@INC contains: /home/savio /etc/perl /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at /usr/lib/cgi-bin/myscript.cgi line 5.
BEGIN failed--compilation aborted at /usr/lib/cgi-bin/myscript.cgi line 5.
[Wed Feb 24 00:45:39 2010] [error] [client 127.0.0.1] Premature end of script headers: myscript.cgi, referer: http://localhost/projects.html
3)
My cgi script is:
Quote:
#!/usr/bin/perl -w
use strict;
use lib '/home/savio/';
use MyModule;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $cgi = CGI->new();
my $pname = $cgi->param('projname');
my $var = new MyModule;
$var->create($pname);
If the script runs cleanly from the commandline, but not when run by the web server, then your web server must not have access to your $HOME tree. Try putting the module in one of the standard places used by Perl, and see if that fixes it. You may be able to grant the user under which the web server runs group read-execute permissions, and then make that user a member of your home group, evidently 'savio'.
Is this host using SElinux? If so try disabling that, at least as a test. I don't know what needs to be done to poke a hole in it if that turns out to be the problem.
Just to be clear, we are talking about directories on the server, right?
Okay, I just did a test of what you are trying to do.
In the server cgi-bin directory:
Code:
4.0K -rwxr--r-- 1 apache root 434 Feb 24 06:55 modTest.pl
In a directory in my $HOME tree:
Code:
4.0K -rwxr--r-- 1 theNbomr theNbomr 251 Feb 24 06:55 MyMod.pm
In /etc/group (note: restart web server after adding apache to user group)
Code:
theNbomr:x:1234:theNbomr,apache
modTest.pl
Code:
#! /bin/perl -w
use strict;
use CGI;
use lib "/home/theNbomr/Util/pl";
use MyMod;
my $page = CGI->new();
my $x = MyMod->new();
print $page -> header, # create the HTTP header
$page -> start_html('hello world'), # start the HTML
$page -> h1('hello world'); # level 1 header
print $x -> tod(); # print time-of-day
print $page -> end_html; # end the HTML
exit;
MyMod.pm
Code:
package MyMod;
use strict;
sub new(){
my $proto = shift;
my $class = ref( $proto ) || $proto;
my $self = {};
bless $self, $class;
return $self;
}
sub tod(){
my $self = shift;
return "ToD : ", my $time = localtime(),"\n";
}
1;
The code works without errors. I think adding the apache user to the theNbomr user group and then restarting the server is the key. Your server may run as a different user.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.