lanta has asked for the wisdom of the Perl Monks concerning the following question:

For a CGI script, I need to use Perl installed in a user directory. The webserver user("apache" in my case) has access to the directory( /home/some_user/perl/bin ) and can stat the files in that location from the command line. While running the script the user is not able to stat the directory. I wrote the following script to test


#!/bin/bash echo Content-type: text/plain echo "" echo "I am " whoami stat /home/some_user

and get the following result
I am Apache stat: cannot stat '/home/some_user': Permission denied.

Any ideas?

Environment
CGI(not mod_perl) Redhat 2.6.32 Apache 2.2.15

Replies are listed 'Best First'.
Re: OT: Local Perl - CGI - Apache.
by stevieb (Canon) on Nov 24, 2015 at 23:46 UTC

    This doesn't appear to be a Perl question... you haven't shown any Perl code... you've shown an inability for your web service user to access a directory structure.

    You say you can stat the directory, but your example shows you can't. (If you can from the CLI, what user are you running the command as (I suspect root), and what is the command?) If your bash script can't stat a file as a user, why would you think this is a perl problem?

    Please post what sudo -u apache ls -la /home/some_user says, as well as sudo -u apache ls -la /home | grep some_user

      stevieb,

      thanks for your time. I understand that this is not a perl question. I need to use the perl interpreter installed in ~some_user, so was hoping some one here might have some config experience with it.

      From the CLI, as apache, I can stat /home/some_user, but not thru the CGI, running under apache.

      # su - apache $ stat /home File: `/home' Size: 4096 Blocks: 8 IO Block: 4096 directory Device: fd00h/64768d Inode: 2097153 Links: 5 Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ roo +t) Access: 2015-11-24 18:30:06.243730150 -0500 Modify: 2014-10-07 22:46:09.353475060 -0400 Change: 2014-10-07 22:46:09.353475060 -0400 -bash-4.1$
      -bash-4.1$ stat /home/some_user File: `/home/some_user' Size: 4096 Blocks: 8 IO Block: 4096 directory Device: fd00h/64768d Inode: 2187307 Links: 43 Access: (0755/drwxr-xr-x) Uid: ( 508/ some_user) Gid: ( 508/ + some_user) Access: 2015-11-24 17:47:08.723747155 -0500 Modify: 2015-11-24 18:34:19.314602725 -0500 Change: 2015-11-24 18:55:24.365823666 -0500

      Once again, thanks in advance for all help

Re: [OT] Apache cannot stat home dirs (was: OT: Local Perl - CGI - Apache.)
by hippo (Archbishop) on Nov 25, 2015 at 09:24 UTC
    Redhat 2.6.32

    That sounds like RHEL 6 to me. In which case, have you set the httpd_enable_homedirs boolean? If you have, still take a look in the audit log to see if the actual reason for the stat failure is there.

    As mentioned by stevieb, this is nothing to do with Perl.

      Thanks hippo. You pointed me in the right direction. Linux was running under SELinux, disabling that fixed the issue. Now, I can look into ways to make it work under SELinux. Regards, lanta.