Programming This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
02-23-2010, 08:38 AM
|
#1
|
|
Member
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 211
Rep:
|
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
|
What is the problem?
Last edited by shifter; 02-23-2010 at 08:42 AM.
|
|
|
|
02-23-2010, 09:02 AM
|
#2
|
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,259
|
The perl interpreter cannot locate your package 'MyModule.pm'.
Code:
#!/usr/bin/perl
use lib "/your/home/dir";
use MyModule;
my $cgi = CGI->new();
my $mProject = new MyModule;
$mProject->create;
--- rod.
|
|
|
|
02-23-2010, 09:45 AM
|
#3
|
|
Member
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 211
Original Poster
Rep:
|
Ok, now it is an other error.
/var/log/apache2/error.log file is:
Quote:
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
|
My createproj.cgi script is:
Quote:
#!/usr/bin/perl
use lib "/my/home/dir/";
use MyModule;
use CGI;
my $cgi = CGI->new();
my $pname = $cgi->param('projname');
my $mProject = new MyModule;
$mProject->create($pname);
|
What is this other problem?
Last edited by shifter; 02-23-2010 at 09:48 AM.
|
|
|
|
02-23-2010, 11:06 AM
|
#4
|
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,259
|
Does the error occur when you run the script from the commandline and with $PWD of /usr/lib/cgi-bin? And, what I should have said right at the start:
Code:
#! /usr/bin/perl -w
use strict;
It may be that the web server has no access to your home directory, and cannot load files from there.
--- rod.
|
|
|
|
02-23-2010, 01:30 PM
|
#5
|
|
Member
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 211
Original Poster
Rep:
|
The output in /var/log/apache2/error.log file is:
Quote:
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$
Firefox output "500 Internal Server Error".
What is the problem?
Last edited by shifter; 02-23-2010 at 01:32 PM.
|
|
|
|
02-23-2010, 03:08 PM
|
#6
|
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,259
|
First, you said
Quote:
|
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.
|
But then you show
Quote:
myname@desktop:/home$ ls -lh
totale 4,0K
drwxr-xr-x 54 myname myname 4,0K 2010-02-23 20:24 myname
|
So, where exactly is MyModule.pm?
Put that directory in the ' use lib' directive, and you should get past the problem.
--- rod.
Last edited by theNbomr; 02-23-2010 at 03:09 PM.
|
|
|
|
02-23-2010, 04:02 PM
|
#7
|
|
Member
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 211
Original Poster
Rep:
|
I added to createproj.cgi
Quote:
|
use lib '/home/myname/MyModule.pm'
|
now works, ok thank you
|
|
|
|
02-23-2010, 05:40 PM
|
#8
|
|
Member
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 211
Original Poster
Rep:
|
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);
|
with MyModule.pm in /home/savio.
What is the problem?
Thanks in advance for answers,
savio
Last edited by shifter; 02-23-2010 at 05:47 PM.
|
|
|
|
02-23-2010, 11:36 PM
|
#9
|
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,259
|
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?
--- rod.
|
|
|
|
02-24-2010, 09:09 AM
|
#10
|
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,259
|
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.
--- rod.
Last edited by theNbomr; 02-24-2010 at 09:13 AM.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:38 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|