PHP Velho Oeste 2024

Fall 4: PHP-Parser außerhalb des Webverzeichnisbaums

Eine sehr sichere Sache ist es, das PHP-Parser-Binary irgendwo außerhalb des Webverzeichnisbaums zu platzieren, beispielsweise in /usr/local/bin. Der einzige Nachteil dieses Verfahrens ist, dass eine Zeile ähnlich der folgenden Zeile:

#!/usr/local/bin/php
als erste Zeile in jeder Datei, die PHP-Tags enthält, stehen muss. Außerdem muss die Datei ausführbar sein. Ansonsten ist sie genauso zu behandeln wie ein beliebiges CGI-Script in Perl oder sh oder anderen gebräuchlichen Skriptsprachen, die den #!-shell-escape-Mechanismus nutzen, um sich selbst aufzurufen.

Damit PHP bei dieser Konfiguration die PATH_INFO- und PATH_TRANSLATED-Informationen korrekt auswertet, muss die Konfigurationsdirektive cgi.discard_path aktiviert werden.

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