读取权限php到python,linux系统

I'm having troubles understanding the permission system when running python scripts from php. It seems quite subtle, I will try and simplify the question as much as possible.

The situation is as follows. I have:

  • a python script myscript.py located in /var/www/
  • a php script myscript.php located in /var/www/
  • a file foo.txt located in /home/some_folder/. Important: foo.txt has 'r' permissions only.

in myscript.php:

exec('python myscript.py')

in myscript.py:

f = open('/home/some_folder/foo.txt', 'r')

Test 1

Running myscript.py from the command line in /var/www/: it does open foo.txt, nevermind its location.

Test 2

Running myscript.php: foo.txt is not opened.

Test 3

Changing the location of foo.txt to /var/www/, changing myscript.py accordingly and running myscript.php : foo.txt is opened.

So... Here I am trying to understand what is wrong with test 2: reading permissions are given, so what could possibly be happening that prevents the python script from doing its job?

This is more out of curiosity since workarounds are easy to find. But I'm troubled and don't understand these things enough to come up with a decent idea why it doesn't work. I'm sure some of you will and I do thank them in advance :)