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.

This question may sound trivial, but it's been giving me trouble. I've written two simple php scripts for a web interface, and they only work with other being given read and execute permissions. I don't understand why the read permission is necessary. Can someone explain or direct me to a reference?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

PHP isn't executed it is 'interpreted' by the php executable. To that end your .php files do not need to have execute permission set. They do though have to be read by the php interpreter so they have to have read permission set.

share|improve this answer
2  
The exception being if you write a PHP shell script (#!/usr/bin/php - style) to run from the command line or as a CGI, but I can't think of a reason anyone would want to do that in normal circumstances. –  voretaq7 Jul 29 '11 at 17:01
    
Thanks! That explains it. –  Yitzchak Jul 29 '11 at 17:28
    
Even when run as a shell script, you still need read permission to be able to send the contents of the file to the interpreter. –  Allan Jude Jul 29 '11 at 21:14
    
@AllanJude: You're right but php filename.php doesn't where as ./filename.php does. –  Iain Jul 29 '11 at 21:26

The webserver and the php executable that is calling it needs to be able to read the source code so it can bytecompile the code and execute it. If php and/or the apache server is running as a different user then your site index files need to be readable.

share|improve this answer

Some web servers use the execute bit as a 'magic' marker to know that the file should be interpreted rather than just returned to the user as-is. This is not the default behaviour for php in Apache, but it used to be an option of perl as a CGI.

share|improve this answer

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.