1 Installation
The yum or apt-Get method is not described here. The following describes the source code installation problems.
In Linux, the source code is usually installed. /configure; Make; make install. however, because different versions depend on different packages, you need to install the corresponding dependencies during the installation process.
1.1 installation path
When installing httpd for Apache, you need to pay attention to the installation path. Due to the large number of Linux system branches, files will be installed in different paths during the installation process. For this reason, Apache can configure these path parameters during installation, specifically through the configure parameter.
-- Prefix: Specifies the root directory for installation. The default value is/usr/local/apache2. You can specify the root directory by yourself. During the make install operation, binlib and others will be installed in this directory, for more details, you can set the following important parameters.
-- Bindir = dir user executables [eprefix/bin]
-- Sbindir = dir system admin executables [eprefix/sbin]
-- Libexecdir = dir program executables [eprefix/libexec]
-- Sysconfdir = dir read-only single-machine data [prefix/etc]
-- Libdir = dir object code libraries [eprefix/lib]
To simplify the configuration process, the source code package provides the config. layout: you can modify the template defined in it and define your directory path through -- enable-layout = 'name' in configure.
Config. layout defines many templates, which are basically defined for each type of system, such as Debian, Mac OS, Aix, and so on. The following shows a default definition of Apache.
<Layout RedHat> prefix: /usr exec_prefix: ${prefix} bindir: ${prefix}/bin sbindir: ${prefix}/sbin libdir: ${prefix}/lib libexecdir: ${prefix}/lib/apache mandir: ${prefix}/man sysconfdir: /etc/httpd/conf datadir: /var/www installbuilddir: ${datadir}/build errordir: ${datadir}/error iconsdir: ${datadir}/icons htdocsdir: ${datadir}/html manualdir: ${datadir}/manual cgidir: ${datadir}/cgi-bin includedir: ${prefix}/include/apache localstatedir: /var runtimedir: ${localstatedir}/run logfiledir: ${localstatedir}/log/httpd proxycachedir: ${localstatedir}/cache/httpd</Layout>
When httpd is installed in yum in the RedHat/centos/Fedora system, it is actually stored in the RedHat layout defined in layout.
1.2 Special configuration during installation
Apache itself is modular. During configuration, we can select the modules supported by Apache and the Support Methods for modules, such as so or static.
-- Enable-modules = mod-list can be replaced by all or most, indicating the statically compiled module.
-- Enable-mod-shared = mod-list is the same as above, which indicates the shared modules that are compiled as dynamic loads.
For more information, see section 3rd.
Generally, a module has many features and features can be enabled and disabled through configuration. You can view the features through configure -- help, as shown in figure
-- Enable-charset-lite supports character conversion.
-- Enable-Deflate supports Compression
-- Enable-LDAP supports LDAP
-- Enable-UserTrack supports user session tracking
The MPM function is supported here. This module is used to control the process usage model. During configuration, you can specify which process model to compile as a static module. Different systems have different default mpm
-- With-MPM = {BEOs | event | worker | prefork | mpmt_os2 | winnt} winnt supported in UNIX
In version 2.4, mpm supports dynamic compilation. You can use the -- enable-MPMs-shared method to describe and then load different MPM modules in the loadmodule,
For details, refer to the official documentation: http://httpd.apache.org/docs/2.4/mpm.html
1.3 compile and install
After you confirm the configuration parameters, execute configure to generate the makefile
Then execute make and make install.
In this way, you can see the installed files in the directory specified by layout.
2. httpd operation control and status monitoring
2.1 HTTPd process control
One way is to directly operate the HTTPd process. You can directly run the command and add appropriate parameters. Terminate with pkill or kill
One way is to use the apachectl script, which is actually a simple packaging of httpd. To set some system environments, set the number of opened file descriptors, and obtain the Process status through system commands.
Start httpd and open your browser. If a file access permission error is prompted, there may be three problems: 1 SELinux policy 2 directory permission configuration error 3 serverroot and superior directory permission Error
2.2 httpd parameter description
-K start | restart | graceful-Stop | stop controls the start and termination of the HTTPd process
-D dir: Specify the serverroot path.
-F file specifies the httpd. conf file path for startup. Multiple Apache processes can be started by specifying different configuration files and ports.
-L list the modules compiled into Apache
-L list the current configuration instructions
-M: list the currently loaded modules.
-D. You can use the command line to set a macro and pass it to <ifdefine Name>... </ifdefine> in the configuration file to achieve selective configuration loading.
-T check the configuration file but do not start
-C/-C transmits configuration commands to httpd to modify static configurations.
2.3 Apache running status monitoring
2.3.1 built-in module support
Mod_status and mod_info provide monitoring of the running status and configuration information. To enable them, you need to enable the corresponding configuration in the configuration file.
## Allow server status reports generated by mod_status,# with the URL of http://servername/server-status# Change the ".example.com" to match your domain to enable.#<Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from .example.com</Location>## Allow remote server configuration reports, with the URL of# http://servername/server-info (requires that mod_info.c be loaded).# Change the ".example.com" to match your domain to enable.#<Location /server-info> SetHandler server-info Order deny,allow Deny from all Allow from .example.com</Location>
Modify the preceding configuration and open http: // usr/Server-status in the browser.
2.3.2 monitoring of third-party tools
Many open-source tools, such as zabbix and Nagios, are not described here
3. Apache module Management and Support
3.1 Module type
Apache modules are divided into three types: core modules, standard modules and third-party modules.
Core Module: such as core and MPM. It is a basic required module of Apache and cannot be deleted.
Standard module: It is maintained by Apache and released as part of Apache. It can be loaded and deleted, provided that the mod_so module must be installed statically.
Third-party module: Developed by a third party and released together with Apache
3.2 Module Loading
The module can be compiled to httpd in a static manner to improve the execution speed. By specifying./configure -- enable-modules = most during configuration
The module can also be dynamically loaded to reduce the size of httpd. /configure -- enable-mod-shared = most, so that we can go to httpd. to load the required modules.
Loadmodule can load modules under serverroot/modules/in the format of loadmodule xxx_module modules/mod_xxx.so
LoadFile is used to load modules in any location. The format is LoadFile/usr/lib/modules/libphp5.so.
It is worth noting that for the loaded module, the URL is processed in the following first-in-first-out mode.
3.3 new modules added
There are different ways to add a new module. It is easier to download the corresponding. So file, store it to the specified location, and load it through loadmodule.
If you need to compile through source code, you need to do it through apxs. For example, when PHP is compiling, you can specify -- with-apxs2 = path to call the relevant script to generate the generated. So file to the corresponding location
Third-party modules are difficult to compile in static mode. If the module supports compiling to Apache in static mode, you can view the compilation documents.
References
MPM prefork operating principle: http://httpd.apache.org/docs/2.4/mod/prefork.html
Working principle of MPM worker: http://httpd.apache.org/docs/2.4/mod/worker.html
MPM event operating principle: http://httpd.apache.org/docs/2.4/mod/event.html
Apache prefork and workers working principle http://blog.csdn.net/gulaizi/article/details/4005523