Heniek
Heniek

Reputation: 573

Apache doesn't see pm file

I have installed Apache 2.2 and strawberry perl. I have textxx.pm. And I prepare simple script

#!/usr/bin/perl
use textxx;
print("HelloWorld!");

When I run it via cmd it works. When I run it via web browser I get and error: Can't locate textxx.pm in @INC (@INC contains: C:/strawberry/perl/site/lib C:/strawberry/perl/vendor/lib C:/strawberry/perl/lib .)

It's weird because script without "use" works.

My module is located at the same directory as script

Upvotes: 1

Views: 1005

Answers (2)

ikegami
ikegami

Reputation: 385976

Lack of permission could be the issue, but I'm betting the problem is that you're expecting Perl to look in the directory containing the script for the module. Perl doesn't do that, at least not by default.

It worked from the console because you set the current work directory happened to the be the same as the script, but that's not the case when you're running it through apache.

To tell Perl to look in the same directory as the script, add the following because use textxx;:

use Cwd qw( realpath );
use File::Basename qw( dirname );
use lib dirname(realpath($0));

Upvotes: 1

xblitz
xblitz

Reputation: 673

You are trying to use the textxx.pm perl module.. but it is not found while running through apache, if you remove the use line it will obviously work since it's not looking for the module.

a quick fix, if your textxx.pm is in let's say C:/strawberry/perl/site/lib then just add this at the top of your script:

#!/usr/bin/perl
use lib "C:/strawberry/perl/site/lib";
use textxx;
print("HelloWorld!");

Upvotes: 2

Related Questions