Linux-install the mod_php5 module to implement apache's support for php. How can this problem be solved ??

Source: Internet
Author: User
Tags apache php sapi unix domain socket
Does php have its own parser? Apache only maps the url request to the disk file of the local server and finds that the file is. php will be handed over to the php parser (this process has nothing to do with apache now) The user of apache (www-data) you must have read permission on the file... does php have its own parser?
Apache only maps the url request to the disk file of the local server. If it finds that the file is. php, it will be handed over to the php parser (this process will not be related to apache at the moment)
The user (www-data) of apache needs to have the permission to read the file, and then the php parser executes the script.
Submit the execution result (dom document) to apache,
Apche then returns the dom document as it is (some response headers may be added) to the client browser.
The client browser receives the dom document and loads the js engine for line-by-line parsing. Only when special labels such as img are met will the client send a request to the server again...

What I understand is that apache is only responsible for passing the assignment? Ask the predecessors to point out what I do not understand

Reply content:

Does php have its own parser?
Apache only maps the url request to the disk file of the local server. If it finds that the file is. php, it will be handed over to the php parser (this process will not be related to apache at the moment)
The user (www-data) of apache needs to have the permission to read the file, and then the php parser executes the script.
Submit the execution result (dom document) to apache,
Apche then returns the dom document as it is (some response headers may be added) to the client browser.
The client browser receives the dom document and loads the js engine for line-by-line parsing. Only when special labels such as img are met will the client send a request to the server again...

What I understand is that apache is only responsible for passing the assignment? Ask the predecessors to point out what I do not understand

From a macro perspective, the implementation of the PHP kernel is the same as that of the vast majority of programs in the world. It receives input data, processes the data, and then outputs (returns) the results. The code we write is the input data received by PHP. The PHP kernel interprets and computes the code and returns the corresponding calculation result.

This problem should be understood from "PHP internal lifecycle" and "SAPI interface:
Let's take a look at the figure:

From the figure, we can see that PHP is a layer-4 system from bottom to top:

Zend engine: Zend is implemented in pure C and is the kernel part of PHP. It translates PHP code (lexical, Syntax Parsing, and other compilation processes) it can process and implement corresponding processing methods, implement basic data structures (such as hashtable and oo), allocate and manage memory, and provide corresponding api methods for external calls, is the core of everything, and all peripheral functions are implemented around Zend.

Extensions: around the Zend engine, extensions provides various basic services in a component-based manner. Our common built-in functions (such as the array series) and Standard libraries are implemented through extension, you can also implement your own extension as needed to achieve function expansion and performance optimization (for example, the PHP middle layer being used by the post bar and Rich Text parsing are typical applications of extension ).

Sapi: The full name of Sapi is Server Application Programming Interface, that is, the Server Application Programming Interface. Sapi enables PHP to interact with peripheral data through a series of hook functions, this is a very elegant and successful PHP design. Through sapi, PHP itself is successfully decoupled from upper-layer applications. PHP can no longer consider how to be compatible with different applications, applications can also implement different processing methods based on their own characteristics.

Upper-layer applications: This is the PHP program we usually write and various application modes are obtained through different sapi methods, for example, you can use webserver to implement web applications and run them in Script Mode under the command line.

Through a series of interfaces, Sapi enables external applications to exchange data with PHP and implement specific processing methods based on different application features. Some common sapis include:

  • Apache2handler: apache is used as the webserver and the processing method used in mod_PHP mode is also the most widely used one.

  • Cgi: This is another direct interaction method between webserver and PHP, namely the famous fastcgi protocol. More and more applications have been made in fastcgi + PHP this year, it is also the only method supported by asynchronous webserver.

  • Cli: Application Mode of command line call

Apache is an open-source Web server of the Apache Software Foundation and can be run in most computer operating systems. It is widely used for cross-platform and security, is one of the most popular Web server software. Apache supports many features, most of which are implemented through module extension. Common modules include mod_auth (permission verification) and mod_ssl (SSL and TLS support) mod_rewrite (URL rewriting. Some common languages also support integration with Apache through the Apache module. Such as Perl, Python, Tcl, and PHP.

When PHP needs to run on the Apache server, it can be integrated in the form of the mod_php5 module. In this case, the mod_php5 module is used to receive PHP file requests passed by Apache and process these requests, then, return the processed result to Apache. If the PHP module (mod_php5) is configured in the configuration file before Apache is started, the PHP module registers the ap_hook_post_config hook of apache2, start this module when Apache starts to accept requests from the PHP file.

First look at some Apache PHP configuration httpd. conf:

LoadModule php5_module modules/libphp5.soAddHandler application/x-httpd-php .php

Libphp5.so/libphp7.so is a module of Apache. The PHP interpreter works in the Apache process (the running users are the same. the php extension file is handed over to the PHP module in the process and the result is returned to the browser. that is to say, Apache loaded into the PHP module is a PHP runtime container, which is a whole and coupled. Therefore, you must compile Apache before using parameters during PHP compilation.--with-apxs2=/png/httpd/2.4/bin/apxsSpecify the Apache module build script and tell Apache that I want to build the PHP module.

For Nginx and PHP-FPM this mode, the landlord needs to take into account the operation of users with different permissions, because Nginx and PHP-FPM are separated, the two are different processes, through TCP or Unix Domain Socket communication, but generally Nginx and PHP-FPM are set to the same running user, so that Nginx and PHP-FPM can have the permission to operate the same file. in addition, the PHP-FPM can also be seen as a PHP container, because the PHP-FPM process is also built into the PHP interpreter, because it does not rely on the command line of php, also does not rely on php-cgi, the difference with Apache is that PHP-FPM is a FastCGI service, while Apache is an HTTP service, Apache can communicate directly with the browser, and PHP-FPM needs to interact with the browser through Nginx.

Digress:
PHP has built an HTTP server Since 5.4. It is officially positioned for development and testing, because this HTTP server is not a general standard HTTP server. For example, it does not support HTTPS, directory List is not supported, and single-process architecture cannot use multiple cores. in addition to development, I also found an interesting application scenario. Since PHP has built-in HTTP server and SQLite database, it can be used as a home Iot server, so I cross-compiled PHP for Android and Raspberry Pi (Raspbian) on Ubuntu, and then wrote an App in Java, and called the command line to start the PHP HTTP server, then open WebView to access the local PHP server. The local PHP is responsible for operating the file system and network. WebView is used for human-computer interaction. Although Java APIs on Android cannot be called, it can do a lot of work. this App is already running on Xiaomi 4.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.