Thursday, March 03, 2011

Apache 2, mod_perl, HTML::Mason, "use lib" and "Can't Locate" issues with @INC

Long title, but accurate. This is a short tidbit for anyone who is experiencing errors with mod_perl relating to being unable to locate modules from a directory in @INC specified via a "use lib" statement.

My personal setup involved an Apache 2 directive within a VirtualHost utilizing HTML::Mason that referenced a "PerlRequire" module that in turn added a specific "use lib" path (/var/www/html/lib) to @INC for use of personal libraries within a new site I had been setting up.

Every single syshandler, autohandler, or page referencing any module within the specified path was crashing with an error that Perl "can't locate" the module in question within the known set of @INC paths (which visibly contained the correct path to the modules in question).

Many hours of Googling found numerous answers suggesting file/directory permission errors, however even setting 777 on every directory and file in question resulted in the same failed outcome.

Almost by accident I checked /var/log/messages and saw something similar to the following:

Mar  3 19:09:21 test_server1 kernel: type=1400 audit(1299197361.362:4):
avc: denied { getattr } for pid=1812 comm="httpd"
dev=dm-0 ino=3342348 scontext=user_u:system_r:httpd_t:s0
tcontext=user_u:object_r:user_home_t:s0 tclass=dir

As soon as I saw this, the light bulb illuminated... This was a new CentOS 5 server and I had forgotten to disable SELinux.

For anyone else experiencing this issue, merely edit /etc/sysconfig/selinux and set "SELINUX=disabled" then reboot, you should be good to go.

The bigger question here is why SELinux would be enabled by default on most servers, but I'll leave that for the philosophers of the world, I've got better things to do.


Anonymous said...

Any idea why I am facing similar issue in windows?

Chris said...

Not enough information for me to really say for sure, but I'd check the usual suspects first (i.e. folder permissions, apache logs, system logs, etc.). I'm not personally running Apache 2 (or anything else involved here) on Windows, but I'd also check to ensure Windows Firewall is disabled and/or any other sort of Anti-Virus type protection that might be acting against your best interests (anti-hacker, etc.).

Are you able to get a basic mason page served and working correctly without the additional @INC path inclusions?