herghost Posted March 27, 2012 Share Posted March 27, 2012 Hi Guys I am struggling with a shell_exec command in the long run, but I am trying to work down the root cause. The error I am getting with shell_exec is a file not found error, so I thought I would start with getting to the right folder. I have this $sym_dir = "/root/"; $cwd = getcwd(); echo getcwd()."\n"; chdir ($sym_dir); echo getcwd()."\n"; Which in theory should 1st display '/var/www' as it does and then display the contents of root, at least that is my understanding! However my return is this /var/www /var/www Why cannot I move outside the web root? Cheers Dave Link to comment https://forums.phpfreaks.com/topic/259826-chdir-outside-of-web-root-on-linux/ Share on other sites More sharing options...
requinix Posted March 27, 2012 Share Posted March 27, 2012 Few reasons. Apache might be chrooted, maybe you don't have permissions. Try going to just /. Link to comment https://forums.phpfreaks.com/topic/259826-chdir-outside-of-web-root-on-linux/#findComment-1331650 Share on other sites More sharing options...
herghost Posted March 27, 2012 Author Share Posted March 27, 2012 Thanks for your reply the following displays all files and folders for / $sym_dir = "/"; echo getcwd()."\n"; chdir ($sym_dir); echo shell_exec("ls -a"); However if I change $sym_dir back to /root/ then I just get the contents of the www folder displayed? Link to comment https://forums.phpfreaks.com/topic/259826-chdir-outside-of-web-root-on-linux/#findComment-1331678 Share on other sites More sharing options...
kicken Posted March 27, 2012 Share Posted March 27, 2012 Most likely you don't have permission to enter /root. It's likely locked down so only the root user can enter it, and apache does not run as root. Link to comment https://forums.phpfreaks.com/topic/259826-chdir-outside-of-web-root-on-linux/#findComment-1331697 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.