views:

333

answers:

3

I'm working on a PHP script that runs a Python script on the server. My server is running CentOS 5.4 with Apache 2.2.3 and PHP 5.1.6.

This is the PHP code:

chdir("/home/cjones/git/pywrapper");
$output = shell_exec("python /home/cjones/git/pywrapper/wrapper.py");

This give me this error:

Warning: chdir() [function.chdir]: Permission denied (errno 13) in /var/www/html/wrapper.php on line 20

In the shell_exec call, I've also tried using "cd /home/cjo... && python ...", but that doesn't work.

The script needs to be run from that directory or it starts throwing errors because it can't find the files it wants. If all else fails, I could just hardcode the paths into the python script instead of using relative paths.

This is the relevant output of ls -l for ~/git

drwxrwxr-x  5 cjones cjones 4096 Mar 23 08:45 pywrapper

I had also tried chmod 777 ~/git/pywrapper but that didn't work. The current setting is just 775.

My best guess is that the apache user for some reason doesn't have access to my user's home directory? But I don't know how to allow it to.

A: 

It is a better idea to have your web site's directory not be in your home directory, but symlink it to e.g. /var/www/mysite.

That said, you can chmod o+x ~; chmod o+x ~/git; #etc. for the directories and chmod o+r ~/git/pywrapper/blablablabla for the files python needs to be able to read when running as Apache.

janmoesen
A: 

What are your safe_mode and open_basedir settings in the php.ini?

http://us.php.net/manual/en/features.safe-mode.php

webbiedave
both safe mode and open basedir will speak for themself
Col. Shrapnel
safe_mode is off and open_basedir has no value.
jonescb
A: 

It's not enough to change permissions on just the 'git' and 'pywrapper' directories. Apache will need to be able to access 'cjones' as well. Most Linux boxes default to users' home directories being mode 0700. If you don't want to loosen the permissions to the 0777 level and grant global access, you could change the group ownership to a new group that you and apache share, and grant 0770 to /home/cjones, /home/cjones/git, and /home/cjones/pywrapper

Marc B