Detailed explanation of the relationship and functions of php and apache

不言
Release: 2023-03-24 19:52:01
Original
1535 people have browsed it

The content of this article is about a detailed explanation of the relationship and role of php and apache. It has a certain reference value. Now I share it with you. Friends in need can refer to it.

Comprehensive summary of this article The following two articles have been published:
Detailed introduction to the relationship and role of php and apache https://blog.csdn.net/hongweideng/article/details/41723465

Taking Apache server and PHP language as examples to explain the access process of dynamic websites in detail https://www.cnblogs.com/sunscheung/p/4643281.html


Currently, website pages are mainly divided into static pages and dynamic pages, websites composed of purely static pages are relatively rare now. Large websites generally use dynamic website website building technology, and some websites use static webpages and dynamic webpages. coexist.

This article takes Apache server and PHP language as examples to explain the access process of dynamic websites in detail. Let’s jump directly to the topic of this article.



# (1) The client accesses the server-side html file

S1: Through local configuration A good DNS domain name server address looks for a DNS server and resolves the Web host domain name in the website URL to the corresponding IP address in the Linux operating system (Apache is usually used in combination with the Linux operating system) where the Web server is located.

S2: Connect to the server system of the above IP address through HTTP protocol (Hypertext Transfer Protocol), through the default port 80 (the default port is 80, there are also Other ports (generally do not enter the port when entering the URL) request the html file (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. , respond to the client browser (ie the user) with the file content.

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 (due to different browsers' differences in code The interpretation rules will be different, so the final page effects 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. The IP address of the corresponding Web server is parsed through the DNS 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 finds and entrusts the PHP application server to process it (the server must install the PHP application server in advance) , the Apache server hands the PHP file (such as index.php) requested by the user 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 html static code The code is returned to the Apache server, and the Apache server outputs the received html static code 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 Solve

#Read the code and finally render the web page.

(3) The client accesses the MySQL database on the server side

If the user needs to To operate the data in the MySQL database, you need to install the database management software MySQL server on the server side to store and manage website data. Since the Apache server cannot connect 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 resolved 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 the PHP file above, the PHP application server receives the delegation from the Apache server and receives the corresponding PHP file.

S4: The PHP application server opens the php file, connects the MySQL database on this machine or other machines on the network through the database connection code in the php file, and executes the standard in the php program SQL query 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 in the process There is a slight difference.

Related recommendations:

php and Apache installation and configuration examples sharing

The relationship and role of php and apache Detailed explanation

The above is the detailed content of Detailed explanation of the relationship and functions of php and apache. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!