How do mod_php, mod_python, mod_Language work

696 Views Asked by At

Some of the Apache modules are related to programming languages, like mod_php and mod_python. The description is basically "enables usage of php within apache" or "enables usage of python within apache". I'm trying to understand an overview of how these types of "language" modules work.

2

There are 2 best solutions below

0
On BEST ANSWER

Basically, if you install and configure mod_php correctls, a php file inside an apache DirectoryRoot will be executed. Mod_python works similarly.

If you install apache without mod_php and you have foo.php at the root of your htdocs folder then http://yourdomain/foo.php will treat the document as a plain text file. Installing and configuring mod_php will cause the script to be parsed as a php script, and the output to be sent to the browser as opposed to the raw text..

Justin

0
On

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.