


Detailed explanation of the relationship and functions of php and apache
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

To set up a CGI directory in Apache, you need to perform the following steps: Create a CGI directory such as "cgi-bin", and grant Apache write permissions. Add the "ScriptAlias" directive block in the Apache configuration file to map the CGI directory to the "/cgi-bin" URL. Restart Apache.

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 is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

When the Apache 80 port is occupied, the solution is as follows: find out the process that occupies the port and close it. Check the firewall settings to make sure Apache is not blocked. If the above method does not work, please reconfigure Apache to use a different port. Restart the Apache service.

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

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.
