Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
You execute the file called php, not the test.php. The test.php is read and interpreted by file (program) named php (which is actually a symlink). –  takeshin Sep 2 '10 at 17:55
add comment

4 Answers

up vote 6 down vote accepted

Having only execute permission is fine if it is a binary. Scripts must have read permission so that their interpreter can read them.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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).

share|improve this answer
add comment

Yes, scripts (non-binary files) need r+x permission to execute.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.