I have a php file test.php
#!/bin/php
<?php
echo "test";
?>
This file owned by root and its permissions are these
-rwxr-x--x
so 'others' can execute, but cannot read.
When logged in as other user than root and trying to run this file from the command line
php test.php
Got the following error
Could not open input file: test.php
If given +r permission it works.
I thought that only execute permission was needed.
Does a PHP file need read permission to 'others' to be executed in command line?
Note: using Ubuntu 10.04 LTS and PHP 5.3.2
Having only execute permission is fine if it is a binary. Scripts must have read permission so that their interpreter can read them.
if you execute the script directly either using the full path or ./test.php with a shebang line it will need to be executable. If you specify the interpreter (ie. php) it's the interpreter that needs to be able to execute code, so in this case it only needs to be able to read the code.
Yes, the file needs to be readable for the user you try to run it with. On a side note, the executable bit doesn't need to be set if you call it the way you do (
php /path/to/script.php
).Yes, scripts (non-binary files) need r+x permission to execute.