Rotten mud: install apache with the source code, and use apache with the source code.
This article was sponsored by Xiuyi linfeng and first launched in the dark world.
Recently, I want to learn about nagios monitoring. However, nagios and apache are closely integrated. Therefore, this article first describes how to install the apache source code.
To install apache, follow these steps:
1. Install the compiling environment
2. Uninstall the original apache
3. Download and decompress the source code package
4. install apache
5. Test apache
6. view the directory generated by apache installation
7. view the apache configuration file
8. Add apache to system services
1. Install the compiling environment
Before installing apache, We need to install the required software package for compiling apache, as follows:
Yum-y install gcc ++ zlib-devel
Ii. Uninstall the original Apache
Before installing apache in the source code, we need to uninstall the apache that has been installed through the rpm package in the system. As follows:
Rpm-qa | grep httpd
Rpm-e -- nodeps httpd-2.2.15-29.el6.centos.x86_64
Rpm-e -- nodeps httpd-tools-2.2.15-29.el6.centos.x86_64
3. Download and decompress the source code package
Download the apache source code package. This experiment uses apache 2.2.27 as an example. We recommend that you download the apache source code package directly on the apache official website, as follows:
Run the following command to download the apache source package:
Wget http://apache.fayea.com/httpd/httpd-2.2.27.tar.gz
Decompress the downloaded source code package. Because the source code package of tar.gz is downloaded, we have two decompression methods.
Method 1: Decompress the package using gunzip as follows:
Gunzip-c httpd-2.2.27.tar.gz> httpd-2.2.27.tar
-The c parameter does not delete the source file.
Tar-xf httpd-2.2.27.tar
Method 2: Decompress the package using tar as follows:
Tar-zxf httpd-2.2.27.tar.gz
Or tar-xf httpd-2.2.27.tar.gz
4. install apache
To install apache, we must first compile and then install apache.
We can use the configure command to view the help during compilation, as shown below:
./Configure -- help
The specific compilation is as follows:
. /Configure -- prefix =/usr/local/apache2 -- enable-rewrite -- enable-so -- enable-headers -- enable-expires -- with-mpm = worker -- enable-modules = most -- enable-deflate
-- Prefix =/usr/local/apache2 indicates the installation path of apache. The default installation path is/usr/local/apache2.
-- Enable-rewrite: rewrite the URL rule more easily, that is, according to the known URL address, convert it to another desired URL address.
-- Enable-so: Activate the DSO (Dynamic Shared Objects Dynamic sharing target) of the apache service, that is, the Shared module can be compiled and installed in the form of DSO in the future. This module cannot be compiled in the form of DSO.
-- Enable-headers provides control over HTTP request headers.
-- Enable-expires: enables zookeeper to Control the HTTP "Expires:" and "Cache-Control:" headers through the configuration file, that is, the content of website images, js, css, and so on, provides browser cache settings on the client.This is an important option for apache optimization.
-- With-mpm = worker: select the apache mpm mode as worker mode. In worker mode, more threads are used to process requests, so more concurrent requests can be processed. The system resource overhead is based on the process MPM prefork. If this parameter is not specified, the default mode is prefork process mode.This is an important option for apache optimization.
-- Enable-deflate supports content compression and Transmission Encoding. It is generally a site for html, js, css, and other content. Using this parameter will increase the transmission speed and enhance the visitor's access experience.In the production environment, this is an important option for apache optimization.
Make
Make install
After installing apache, check the installed directory as follows:
Tree-L 1/usr/local/apache2/
V. Test apache
Copy the apache STARTUP script to the/etc/rc. d/init. d directory, as shown below:
Cp/usr/local/apache2/bin/apachectl/etc/init. d/httpd
In fact, apache is started by calling the/usr/local/apache2/bin/httpd command to view the script content as follows:
Cat/etc/init. d/httpd | grep-v ^ # | grep-v ^ $
Start apache as follows:
/Etc/init. d/httpd start
Netstat-lntp | grep 80
Lsof-I: 80
You can also use/usr/local/apache2/bin/httpd for startup. As follows:
/Usr/local/apache2/bin/httpd-k start
After apache is started, run the following command:
Wget http: // 192.168.1.213
We can see that apache is started normally.
6. view the directory generated by apache installation
After apache is started normally, let's check the directory generated by apache installation. As follows:
Bin mainly stores the program command directory ,.
Conf stores apache configuration files.
Htdocs stores site directories.
Logs stores default log files.
Modules stores the running modules of apache. For example, php and memcache compiled modules are stored here.
7. view the apache configuration file
The apache configuration file httpd. conf is stored in the conf directory as follows:
View the configuration of httpd. conf as follows:
Egrep-v '^ [] * # | ^ $'/usr/local/apache2/conf/httpd. conf | nl
ServerRoot "/usr/local/apache2" indicates the apache root directory, which must be accessible only by the root user and generally not need to be modified.
Listen 80 indicates the apache listening port. The default value is 80. If you monitor port 81 at the same time, you can add a row: Listen 81.
AddType application/x-httpd-php. php LoadModule php5_module modules/libphp5.so is used for integration of apache and php.
User daemon Group daemon indicates the User and Group when apache is running. The default value is daemon. We recommend that you modify the value, such as apache.
DocumentRoot "/usr/local/apache2/htdocs" indicates the default apache web site directory,Do not add a slash at the end of the path.
The ServerAdmin you@example.com represents the mailbox of the system administrator, which is not an important option. When a problem occurs on the website, the page address is displayed on all pages.
DirectoryIndex index. php index.html: configure the default apache homepage. If the VM is not configured, the configuration here is applied by default.
ErrorLog "logs/error_log" Error Log Path.
LogLevel warn Error Log Level.
ScriptAlias/cgi-bin/"/usr/local/apache2/cgi-bin/" configure the cgi alias.
8. Add apache to system services
To enable apache startup, we can add the apachectl STARTUP script to the rc. local file as follows:
Echo "/usr/local/apache2/bin/apachectl start">/etc/rc. local
Cat/etc/rc. local
We can also start apache by adding apache to the system service. There are two ways to add apache as a system service. The first is to add apache through chkconfig, and the second is to directly add various startup levels of the system.
Let's first introduce the first method. Modify the httpd script and add the following two lines of commands:
# Chkconfig: 2345 70 60
# Description: apache
Note:
Chkconfig: 2345 in 2345 70 60, 2345 indicates the script running level, that is, it can be run in 234 mode, is a text interface, and 5 is a graphical interface X.
70 indicates the sequence number of the script to be started in the future. If the sequence number of other programs is smaller than 70 (such as 44 and 45), the script must be started after these programs are started. 60 indicates the stop sequence number of the script when the system is disabled.
Description: A Brief description of apache scripts.
Use chkconfig to add data as follows:
Chkconfig -- add httpd
Chkconfig | grep httpd
Chkconfig -- add httpdThe command adds/etc/init. d/httpd to the/etc/rc. d/rc0.d directory in/etc/rc. d/rc6.d. As follows:
Find/etc-name * httpd
Run the following command to enable apache startup:
Chkconfig httpd on
Chkconfig | grep httpd
After the above operations, apache can be started.