Apache mod_perl cannot locate startup script

Ex Umbris asked:

Running Centos 6.6 with Apache 2.2.15 and mod_perl 2.0.4

I’m trying to add a startup script (startup.pl) but cannot seem to get
mod_perl to find it. I’ve reduced the config down to the bare minimum
that still reproduces the issue for me.

Apache mod_perl configuration:

LoadModule perl_module modules/mod_perl.so
PerlRequire /home/web/pdxep/startup.pl
PerlSwitches -wT

Contents of /home/web/pdxep/startup.pl

[jhg@perseus pdxep]$ pwd
[jhg@perseus pdxep]$ cat startup.pl
use lib qw(/home/web/pdxep);

When attempting to start Apache:

[Wed Jul 08 16:13:02 2015] [error] Can't locate 
    /home/web/pdxep/startup.pl in @INC (@INC contains: 
        /etc/httpd) at (eval 2) line 1.n
[Wed Jul 08 16:13:02 2015] [error] Can't load Perl file: 
    /home/web/pdxep/startup.pl for server perseus.jhmg.pvt:0, 

As a sanity check to show I’ve verified permissions:

[jhg@perseus pdxep]$ ls -ld / /home /home/web /home/web/pdxep
dr-xr-xr-x. 24 root root   4096 May 26 11:18 /
drwxr-xr-x.  5 root root   4096 Jul  8 14:42 /home
drwxr-xr-x.  3 root root   4096 Jul  8 14:43 /home/web
drwxr-xr-x.  3 jhg  apache 4096 Jul  8 16:04 /home/web/pdxep
[jhg@perseus pdxep]$ ls -l /home/web/pdxep/startup.pl
-rwxr-xr-x. 1 jhg apache 33 Jul  8 16:04 /home/web/pdxep/startup.pl

Also as a sanity check, su to apache and load the startup script:

[jhg@perseus pdxep]$ sudo -s -u apache
bash-4.1$ cd
bash-4.1$ pwd
bash-4.1$ perl -de0

Loading DB routines from perl5db.pl version 1.32
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(-e:1):   0
  DB<1> require '/home/web/pdxep/startup.pl';

  DB<2> x @INC
0  '/home/web/pdxep'
1  '/usr/local/lib64/perl5'
2  '/usr/local/share/perl5'
3  '/usr/lib64/perl5/vendor_perl'
4  '/usr/share/perl5/vendor_perl'
5  '/usr/lib64/perl5'
6  '/usr/share/perl5'
7  '.'

The fact that $INC[0] has that value indicates the startup script executed successfully.

Any suggestions on further troubleshooting?

My answer:

You have SELinux enabled, and in its default configuration it does not allow web servers to access content in user home directories.

To allow the web server to access user files, you need to set the appropriate boolean, httpd_read_user_content:

setsebool -P httpd_read_user_content 1

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.