Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Webserver permissions and PHP

Posted by JimL (JimL), 15 November 2004
A bit of an obscure question:

On our webserver I have noticed that for PHP files to execute, the folder they are in must have executable rights. However, the PHP files themselves don't (they generally only have 664 (rw-rw-r--) permissions).

I find this a little confusing. Surely the PHP file should itself be executable?

Can anyone explain, or does anyone know any links to relevant information?

Cheers,  Jim

Posted by John_Moylan (jfp), 15 November 2004
Now I may be talking complete drivel here, but heres my potentially wrong take on it.

You PHP page/script work when not executable because the webserver reads it, and then parses/executes what it reads and spits out the output of the script to the browser.

A directory must always be executable, otherwise you could not open it, thats why your scripts stop working when the 'x' bit is not turned on i.e. the webserver cannot open the directory.

If you run PHP on the command line and not the webserver thats a different beast. You will need to have the x bit turned on if you invoke your script by name.

for example if the permissions on script .php were
-rw-r--r--
on the command line you cannot just type:
Code:
script.php

and expect it to run. You could tell PHP on the command line to run it though with these permissions with:
Code:
php script.php
Note I actually invoke php here.

If the permissions were
-rwxr-xr-x
then you could just type
Code:
script.php
and it will run as long as you have the path to php at the start of the script
Code:
!#/path/to/php

and you have php in your $PATH (thats another paragraph though and may not be of interest here)

hope this helps
jfp

Posted by JimL (JimL), 15 November 2004
Thanks!

Yes, your reply does make a lot of sense! I didn't realise that the executable permission on the directory was necessary to open the directory!

Also it makes sense that the PHP module just reads the PHP file, and then 'does it's own thing', spouting out the required HTML itself. The PHP file isn't some sort of executable, it's just a set of instructions for the PHP module to read.

Cheers,  Jim



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho