LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 02-23-2010, 08:38 AM   #1
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Rep: Reputation: 30
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.
 
Old 02-23-2010, 09:02 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.
 
Old 02-23-2010, 09:45 AM   #3
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
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.
 
Old 02-23-2010, 11:06 AM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.
 
Old 02-23-2010, 01:30 PM   #5
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
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.
 
Old 02-23-2010, 03:08 PM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.
 
Old 02-23-2010, 04:02 PM   #7
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
I added to createproj.cgi

Quote:
use lib '/home/myname/MyModule.pm'
now works, ok thank you
 
Old 02-23-2010, 05:40 PM   #8
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
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.
 
Old 02-23-2010, 11:36 PM   #9
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.
 
Old 02-24-2010, 09:09 AM   #10
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem getting perl working with apache2 cgi script jabberwok Linux - Server 10 04-17-2009 08:30 AM
cgi with perl or shell script lappy Programming 2 03-08-2009 10:43 PM
Wierd CVS checkout problem from CGI perl script spadesmaster Linux - Software 0 04-27-2007 04:19 PM
PERL: cgi script copy problem from server to another <db> Programming 2 04-16-2006 09:14 PM
Need Help With My Perl/cgi Authentication Script dutch357 Programming 0 04-11-2003 09:54 AM


All times are GMT -5. The time now is 08:36 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration