Home Backend Development PHP Tutorial Detailed explanation of the relationship and functions of php and apache

Detailed explanation of the relationship and functions of php and apache

Apr 26, 2018 am 09:21 AM
apache php effect

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

Why Use PHP? Advantages and Benefits Explained Why Use PHP? Advantages and Benefits Explained Apr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP's Impact: Web Development and Beyond PHP's Impact: Web Development and Beyond Apr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

See all articles