mawriz Posted September 13, 2007 Share Posted September 13, 2007 Hi guys, hope you can help me with this one. My doc root is /home/httpd/html. I have a file called tmp.php in that directory. <?php ini_set("display_errors", "On"); error_reporting(E_ALL); exec('ls /home/kannel/smslogs/', $arrOutput, $intReturn); echo "<pre>"; var_dump($arrOutput); var_dump($intReturn); ?> The permissions for smslogs directory is as follows: drwxr-xr-x 4 kannel kannel 4096 Apr 21 2005 smslogs The code runs well in the console when I type "php tmp.php" but it doesn't work when I run it in the webserver "http://192.168.40.3/tmp.php" Output in console: Content-type: text/html X-Powered-By: PHP/4.3.3 <pre>array(3) { [0]=> string(5) "globe" [1]=> string(5) "smart" [2]=> string(9) "smart.log" } int(0) Output in browser: array(0) { } int(1) It seems the problem is permissions but apache should be able to read the directory because the permission for "others" in smslogs directory is r-x. Any ideas? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/69165-apache-cannot-read-directory-but-permissions-are-correct/ Share on other sites More sharing options...
clearstatcache Posted September 13, 2007 Share Posted September 13, 2007 its because command line path is different with http path or ur path in the browser.....do not use complete path like /home/kannel/smslogs u use relative path.... e.g. if ur tmt.php is in /home/kannel/scripts use "ls ../smslogs" hop ds helps.... Quote Link to comment https://forums.phpfreaks.com/topic/69165-apache-cannot-read-directory-but-permissions-are-correct/#findComment-347652 Share on other sites More sharing options...
mawriz Posted September 14, 2007 Author Share Posted September 14, 2007 Hi thanks for the suggestion, but I've used exec before with absolute paths and I didn't encounter any problems. Infact as a test, I replaced "/home/kannel/smslogs/'" with "/home/kannel/" and amazingly it worked which only added to my confusion, because it would mean that the smslogs directory is the problem, but this directory is readable by everyone (see first post for smslogs directory permissions). Also, I replaced ls with /bin/ls. Here's the result of my test when I replaced "/home/kannel/smslogs/" with "/home/kannel/": array(139) { [0]=> string(2) "~." [1]=> string(17) "02admucmp-jmx.sar" [2]=> string(26) "02admucmp-jmx.sar-20060113" [3]=> string(26) "02admucmp-jmx.sar-20060713" [4]=> string(26) "02admucmp-jmx.sar-20060921" [5]=> string(33) "02admucmp-jmx.sar-working11022005" [6]=> string(17) "03admucmp-ejb.jar" [7]=> string(26) "03admucmp-ejb.jar-20060113" ... ... ... The permissions for kannel directory is as follows: drwxr--r-- 44 kannel kannel 8192 Sep 13 14:10 kannel I still can't understand why php could not read the smslogs directory. Quote Link to comment https://forums.phpfreaks.com/topic/69165-apache-cannot-read-directory-but-permissions-are-correct/#findComment-348200 Share on other sites More sharing options...
btherl Posted September 14, 2007 Share Posted September 14, 2007 You haven't got SELinux enabled have you? Quote Link to comment https://forums.phpfreaks.com/topic/69165-apache-cannot-read-directory-but-permissions-are-correct/#findComment-348214 Share on other sites More sharing options...
mawriz Posted September 14, 2007 Author Share Posted September 14, 2007 Nope, SELinux is disabled. Quote Link to comment https://forums.phpfreaks.com/topic/69165-apache-cannot-read-directory-but-permissions-are-correct/#findComment-348264 Share on other sites More sharing options...
effigy Posted September 14, 2007 Share Posted September 14, 2007 Redirect STDERR to STDOUT so you can see any errors: ls /home/kannel/smslogs 2>1 Quote Link to comment https://forums.phpfreaks.com/topic/69165-apache-cannot-read-directory-but-permissions-are-correct/#findComment-348390 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.