PHP Velho Oeste 2024

Вариант 4: PHP вне дерева веб-документов

Один из способов существенно повысить уровень безопасности - поместить исполняемый модуль PHP вне дерева веб-документов, например в /usr/local/bin. Единственным недостатком такого подхода является то, что первая строка каждого скрипта должна иметь вид:

#!/usr/local/bin/php
Также необходимо сделать все файлы скриптов исполняемыми. Таким образом, скрипт будет рассматриваться так же, как и любое другое CGI-приложение, написанное на Perl, sh или любом другом скриптовом языке, который использует #! в начале файла для запуска самого себя.

Для корректной обработки PHP переменных PATH_INFO и PATH_TRANSLATED директива ini cgi.discard_path должна быть включена.

add a note add a note

User Contributed Notes 2 notes

up
-7
Anonymous
10 years ago
To add a new structure out the PHP directory, you have to do first:

- Configure the .ini file
- Add to your IDE the interpretor
up
-9
terom at fixme dot fi
10 years ago
You can use binfmt-misc to avoid the need for the #! line, by registering your php5-cgi binary as an interpreter for *.php files. E.g. with Debian binfmt-misc installed:

    update-binfmts --install php5 /usr/bin/php5-cgi --extension php
    cat /proc/sys/fs/binfmt_misc/php5

However, you still need chmod +x on the .php file. And Apache will give a rather sad "500 Internal Server Error" if you are missing the +x permissions :( You can improve the error message using mod_rewrite (but not obliviate the need for +x)..
To Top