(php/apache beginner here)
Intro
Using Apache(as a service on Windows) with PHP I've realized that while by default the web-user can only access the \htdocs
contents, the PHP script itself can read anywhere (not limited inside \htdocs
). What happens if we are not sure about the content of the PHP script though and wish to restrict file-system access?
Problem
Assume that we wish to allow people to change the content of the .php files but at the same time apply filesystem level restrictions. eg: script1.php
can read/write/execute anything in c:\apache\htdocs
. It can read-only from c:\f1\
but can NOT access any other directory altogether.
Question
How can one make sure that his/her PHP program has very specific permissions in windows when reading or writing (eg with file_exists()
, mkdir()
, proc_open()
, fwrite()
, GD:imagejpg()
) when outside \htdocs
?
additional thoughts
I've read that apache as a service runs as the LocalSystem
account that has full read and write (777
) permissions on most local paths.1
- Would it be right if I created a new (virtual?) User Account, assigned it to the apache service and change the [rwx] permissions of that particular account to my liking?
- Is there a way to create different sets of restrictions for different PHP scripts? eg. besides
c:\apache\htdocs
,script1.php
is also allowed to read-write inc:\f1
while script2.php is allowed to read-only fromc:\f2
- Moreover, would it be possible to create a "permission manager" - a PHP script that when executed, assigns rights to other php scripts? eg all .php scripts that are less than 120bytes, can read-write in
c:\f1
Thank you for your time,
-Fotis