PHPKonf Istanbul PHP Conference 2019 - Call for Papers

情形四:PHP 解释器放在 web 目录以外

一个非常安全的做法就是把 PHP 解释器放在 web 目录外的地方,比如说 /usr/local/bin。这样做唯一不便的地方就是必须在每一个包含 PHP 代码的文件的第一行加入如下语句:

还要将这些文件的属性改成可执行。也就是说,要像处理用 Perl 或 sh 或其它任何脚本语言写的 CGI 脚本一样,使用以 #! 开头的 shell-escape 机制来启动它们。

在这种情况下,要使 PHP 能正确处理 PATH_INFOPATH_TRANSLATED 等变量的话,在编译 PHP 解释器时必须加入 --enable-discard-path 参数。

add a note add a note

User Contributed Notes 2 notes

4 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
terom at fixme dot fi
4 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