0

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?

3

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.

3
  • 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
  • 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.
    – user9517
    Jul 29 '11 at 21:26
1

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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