The relationship between apache and php
Taking the Apache server and php language as an example to explain the access process of dynamic websites https ://www.cnblogs.com/sunscheung/p/4643281.html
At present, website pages are mainly divided into static pages and dynamic pages. Websites composed of purely static pages are relatively rare now. Large websites Dynamic website building technology is generally used, and some websites have static web pages and dynamic web pages coexisting.
This article takes Apache server and PHP language as examples to explain in detail the access process of dynamic websites. Let’s jump directly to the topic of this article.
Recommended: "PHP Tutorial"
(1) The client accesses the server-side html file
S1: Through this Find the DNS server address configured by the machine, and resolve the Web host domain name in the website URL to the corresponding IP address in the Linux operating system where the Web server is located (Apache is usually used in combination with the Linux operating system).
S2: Connect to the server system of the above IP address through HTTP protocol (Hypertext Transfer Protocol), and request through the default port 80 (the default port is 80, there are other ports, and you generally do not need to enter the port when entering the URL) HTML files (such as index.htm) in the corresponding directory on the Apache server.
S3: After the Apache server receives the user's access request, it finds and opens the corresponding html file (such as index.htm) in the document directory it manages, and responds to the client browser (i.e. user).
S4: After the browser receives the response from the web server, it receives and downloads the server-side html static code, and then the browser interprets the code and finally renders the web page (because different browsers have different rules for interpreting codes) are different, so the final page effect rendered by different browsers for the same web page will be different).
(2) The client accesses the server-side php file
S1: This step is the same as accessing the html static web page above, and the corresponding Web page is parsed through the DNS server The IP address of the server.
S2: It is similar to accessing the html static page above, but the final request is the php file in the corresponding directory on the Apache server, such as index.php.
S3: The Apache server itself cannot process the PHP dynamic language script file, so it looks for and entrusts the PHP application server to process it (the server must install the PHP application server in advance). The Apache server will process the PHP file requested by the user (such as index.php) file to the PHP application server.
S4: The PHP application server receives the php file (such as index.php), opens and interprets the php file, and finally translates it into html static code, and then returns the html static code to the Apache server, and the Apache server will receive the The html static code is output to the client browser (i.e. the user).
S5: Same as accessing the html static page above. After the browser receives the response from the web server, it receives and downloads the server-side html static code, and then the browser interprets the code and finally renders the web page.
(3) The client accesses the MySQL database on the server side
If the user needs to operate the data in the MySQL database, then the database management software needs to be installed on the server side MySQL server, used to store and manage website data. Since the Apache server cannot connect to and operate the MySQL server, you also need to install the PHP application server. In this way, the Apache server entrusts the PHP application server to connect and operate the database. When managing the data in the database, you generally need to use structures. Query statement, that is, SQL statement.
S1: This step is the same as accessing the php file above. The IP address of the corresponding Web server is parsed through the DNS server.
S2: Just like accessing the php file above, request access to the php file in the corresponding directory on the Apache server.
S3: Just like accessing PHP files above, the PHP application server receives the delegation from the Apache server and receives the corresponding PHP files.
S4: The PHP application server opens the php file, connects to the MySQL database on this machine or other machines on the network through the database connection code in the php file, and executes standard SQL queries in the php program statement to obtain the data in the database, and then generate html static code from the data through the PHP application server.
S5: After the browser receives the response from the web server, it receives and downloads the server-side html static code, and then the browser interprets the code and finally renders the web page.
It should be noted that the difference between (2) and (3) in the article is that one accesses the database and the other does not access the database, so there is a slight difference in the process.
The above is the detailed content of The relationship between apache and php. For more information, please follow other related articles on the PHP Chinese website!