Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Problem with directory path checking

by mahira (Acolyte)
on Jan 11, 2012 at 17:14 UTC ( [id://947384]=perlquestion: print w/replies, xml ) Need Help??

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

Dear Monks,

I've just switched to a shiny new CentOS 6 server and installed Perl 5.10 on it.

Then I moved one of my web sites to this new server.

Now I have a strange problem...

Somewhere in my perl code I check for a directory path if it is available with the code below...

if (-d '/home/bla/public_html/blabla') { print 'OK' }

The directory is available but cannot found. It is existing (I also checked from the terminal) and this sample code working fine o the previous server (CentOS 5.6 + Perl 5.8.8)

One strange thing too...If I write the code below it finds the path:

if (-d '/home/bla') { print 'OK' }

I am desperately seeking for help. I've googled since hours but :((

Replies are listed 'Best First'.
Re: Problem with directory path checking
by MidLifeXis (Monsignor) on Jan 11, 2012 at 17:19 UTC

    Does the user your web server is running under have permissions to the directory in question (including all parent directories)?

    --MidLifeXis

      Yes "apache" (the user of the web server) is a member of the directories owner group.

        How about /home/bla/public_html/blabla and /home/bla/public_html? Also, group membership does not mean that the user will have proper permissions. See also if there are ACL entries and what the group permissions are on each of the directories.

        Are CGI scripts running with suEXEC permissions to a different user?

        It might help to diagnose this if you were to show us what the process entry looks like for the script that is misbehaving, what the directory entries between /home/blah and /home/blah/public_html/blabla look like, and anything else that may be pertinent. With what you have provided, the best we can do is like throwing darts at a target while being blindfolded.

        --MidLifeXis

        Note that permissions on all of the ancestor directories also matter.

        To aid in diagnosing the problem, you might want to do something like the following:

        my $dir = '/home/bla­/public_ht­ml/blabla'­; my $isDir = -d $dir; if( $isDir ) { print "Found directory: $dir\n"; } elsif( defined $isDir ) { print "Found non-directory: $dir\n"; } else { print "Can't stat($dir): $!\n"; }

        That way you can distinguish between "permission denied" vs "no such file/dir" vs something more exotic. The next step narrows down the source of the problem:

        use File::Basename 'dirname'; my $dir = '/home/bla­/public_ht­ml/blabla'­; my $isDir; while( ! defined $isDir ) { my $isDir = -d $dir; if( $isDir ) { print "Found directory: $dir\n"; } elsif( defined $isDir ) { print "Found non-directory: $dir\n"; } else { print "Can't stat($dir): $!\n"; } last if '/' eq $dir; $dir = dirname( $dir ); }

        - tye        

Re: Problem with directory path checking
by moritz (Cardinal) on Jan 11, 2012 at 18:05 UTC

    Just a speculation...

    Find out whether you have selinux installed and enabled.

    If that's the case, it likely restricts apache to a www context. That might prevent it from reading directories under the user's home dir.

      No it is disabled :(

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://947384]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-03-19 03:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found