I will write more about this article, mainly because it is time to finish. Recently, I have been busy with my work. I have to deal with a big mess in the company. First, I have to show off and eat it. Second, I can write something when I am idle. When there is little gossip, the book is connected back:
LApache Lifecycle
This section describes the loading process of the PHP module. For details, refer to Apache lifecycle (in prefork mode ).
Apache runs in the startup and running stages.
1.Startup phase
In the startup phase, Apache mainly parses configuration files (for example, HTTP. conf and include command configuration files), module loading (such as mod_php.so, mod_perl.so), and System Resource Initialization (such as log files and shared memory segments.
In this phase, Apache will start as a privileged user root (x system) or super administrator (Windows System) to obtain the maximum permission to use system resources.
ApacheAnd "phpThe assembly process of the processor is completed at this stage.
"PhpThe processor is responsible for interpreting and executing your phpThe system module of the Code. I created this name specifically to help you understand the content of this section. The following sections will also provide more professional names.
Have you installed and configured PHP separately?
If you have done similar work, the following content is easy to understand; if you have not done it, you can try to install it to help you better understand it. However, my article has always been in-depth and I will try to make it easier. In fact, PHP installation is very simple. If you are very interested, you can search for an installation guide on the Internet and follow the steps.
To integrate PHP into Apache, you also need to make some necessary settings for Apache. Here, we will take the mod_php5 SAPI running mode of PHP as an example. The SAPI concept will be explained in detail later.
Assume that the installed versions are apache2 and PhP5. Edit the main configuration file HTTP. conf of Apache and add the following lines to it:
Unix/LinuxEnvironment:
Loadmodule php5_module modules/mod_php5.so
Addtype application/X-httpd-PHP. php
Note: modules/mod_php5.so is the installation location of the mod_php5.so file in the X system environment.
WindowsEnvironment:
Loadmodule php5_module D:/PHP/php5apache2. dll
Addtype application/X-httpd-PHP. php
Note: D:/PHP/php5apache2. dll is the installation location of the php5apache2. dll file in windows.
These two configurations tell the Apache serverURL received laterFor user requestsAs a suffix, you need to call php5_moduleModule (mod_php5.so/php5apache2. dll.
You can refer to the following process:
The source code of the Apache startup phase is included in server/Main. c. I sorted out the correspondence in the source code:
If you are not familiar with Unix/Linux, you may ask what kind of file is the so file (mod_php5.so?
In Unix/Linux, The so suffix file is a DSO file, and the DLL in DSO and Windows systems is equivalent. They all encapsulate a bunch of functions in a binary file. After the processes that call them load them into the memory, they are mapped to their own address space.
DSO is called a dynamic shared object, that is, a dynamic shared object. DLL is called dynamic link library, which is a dynamic link library.
The most important feature of the Apache server architecture is its highly modular architecture. If you want to achieve processing efficiency, you can link these DSO modules statically at Apache compilation, which will improve the processing performance of Apache by about 5%.
2.Running stage
In the running stage, Apache mainly processes users' service requests.
At this stage, Apache abandons the privileged user level and uses common permissions. This is mainly based on security considerations to prevent security vulnerabilities caused by code defects, microsoft's IIS has been attacked by "Code Red" and "Nimda" and other malicious code overflow attacks.