一些 Apache 模块与编程语言相关,例如 mod_php 和 mod_python。描述基本上是“允许在 apache 中使用 php”或“允许在 apache 中使用 python”。我试图了解这些类型的“语言”模块如何工作的概述。
2 回答
This is relatively simple; When the webserver starts, it will register modules within its core. Language interpreter modules, like mod_php, will register a hook within the page request handler.
This means when a user requests a page, the webserver will pass the request to the module, which checks if the requested file is a type that is registered to be executed by the parser behind the module. In PHP's case you are most likely adding "AddType application/x-httpd-php .php" or similar to the httpd.conf file, which mod_php, will take into account when parsing such requests.
PHP is now in control of the request, which will read the file, parse, compile and execute it and then return it to the request buffer which the webserver will serve as content.
Same goes for other modules, although their handling of a request is different, they all do the same thing.
基本上,如果您正确安装和配置 mod_php,则会执行 apache DirectoryRoot 中的一个 php 文件。Mod_python 的工作原理类似。
如果您安装没有 mod_php 的 apache,并且您的 htdocs 文件夹的根目录中有 foo.php,那么http://yourdomain/foo.php会将文档视为纯文本文件。安装和配置 mod_php 将导致脚本被解析为 php 脚本,并将输出而不是原始文本发送到浏览器。
贾斯汀