欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

HTTPD ( apache ) WEB 服务器——HTTPD 安装

程序员文章站 2022-06-12 13:22:22
...

centos6 中安装HTTPD

HTTPD 服务是 Apache 基金会的经典开源项目,同时作为 web 服务器他加速了 Linux 在服务器领域的推广和普及。

CentOS6.10 中安装默认 yum 源中的 http2.2.15 版本

[aaa@qq.com ~]#service iptables stop 
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[aaa@qq.com ~]#service iptables status
iptables: Firewall is not running.
[aaa@qq.com ~]#getenforce 
Disabled
[aaa@qq.com ~]#
[aaa@qq.com ~]#cat /etc/redhat-release 
CentOS release 6.10 (Final)
[aaa@qq.com ~]#
[aaa@qq.com ~]#yum list http*
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Installed Packages
httpd-tools.x86_64                 2.2.15-69.el6.centos                   @anaconda-CentOS-201806291108.x86_64/6.10
Available Packages
http-parser.i686                   2.0-4.20121128gitcd01361.el6           epel                                     
http-parser.x86_64                 2.0-4.20121128gitcd01361.el6           epel                                     
http-parser-devel.i686             2.0-4.20121128gitcd01361.el6           epel                                     
http-parser-devel.x86_64           2.0-4.20121128gitcd01361.el6           epel                                     
httpd.x86_64                       2.2.15-69.el6.centos                   centos6                                  
httpd-devel.i686                   2.2.15-69.el6.centos                   centos6                                  
httpd-devel.x86_64                 2.2.15-69.el6.centos                   centos6                                  
httpd-itk.x86_64                   2.2.22-7.el6                           epel                                     
httpd-manual.noarch                2.2.15-69.el6.centos                   centos6                                  
httping.x86_64                     2.4-1.el6                              epel                                     
httpry.x86_64                      0.1.8-1.el6                            epel                   

[aaa@qq.com ~]#rpm -qi httpd
package httpd is not installed
[aaa@qq.com ~]#

[aaa@qq.com ~]#yum install httpd -y         #安装默认的httpd服务
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.2.15-69.el6.centos will be installed
--> Processing Dependency: httpd-tools = 2.2.15-69.el6.centos for package: httpd-2.2.15-69.el6.centos.x86_64
--> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-69.el6.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.2.15-69.el6.centos.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.2.15-69.el6.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.2.15-69.el6.centos.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.3.9-5.el6_9.1 will be installed
---> Package apr-util.x86_64 0:1.3.9-3.el6_0.1 will be installed
---> Package apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 will be installed
---> Package httpd-tools.x86_64 0:2.2.15-69.el6.centos will be installed
---> Package mailcap.noarch 0:2.1.31-2.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================
 Package                     Arch                 Version                              Repository             Size
===================================================================================================================
Installing:
 httpd                       x86_64               2.2.15-69.el6.centos                 centos6               836 k
Installing for dependencies:
 apr                         x86_64               1.3.9-5.el6_9.1                      centos6               124 k
 apr-util                    x86_64               1.3.9-3.el6_0.1                      centos6                87 k
 apr-util-ldap               x86_64               1.3.9-3.el6_0.1                      centos6                15 k
 httpd-tools                 x86_64               2.2.15-69.el6.centos                 centos6                81 k
 mailcap                     noarch               2.1.31-2.el6                         centos6                27 k

Transaction Summary
===================================================================================================================
Install       6 Package(s)

Total download size: 1.1 M
Installed size: 3.7 M
Downloading Packages:
(1/6): apr-1.3.9-5.el6_9.1.x86_64.rpm                                                       | 124 kB     00:00     
(2/6): apr-util-1.3.9-3.el6_0.1.x86_64.rpm                                                  |  87 kB     00:00     
(3/6): apr-util-ldap-1.3.9-3.el6_0.1.x86_64.rpm                                             |  15 kB     00:00     
(4/6): httpd-2.2.15-69.el6.centos.x86_64.rpm                                                | 836 kB     00:00     
(5/6): httpd-tools-2.2.15-69.el6.centos.x86_64.rpm                                          |  81 kB     00:00     
(6/6): mailcap-2.1.31-2.el6.noarch.rpm                                                      |  27 kB     00:00     
-------------------------------------------------------------------------------------------------------------------
Total                                                                              2.3 MB/s | 1.1 MB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : apr-1.3.9-5.el6_9.1.x86_64                                                                      1/6 
  Installing : apr-util-1.3.9-3.el6_0.1.x86_64                                                                 2/6 
  Installing : httpd-tools-2.2.15-69.el6.centos.x86_64                                                         3/6 
  Installing : apr-util-ldap-1.3.9-3.el6_0.1.x86_64                                                            4/6 
  Installing : mailcap-2.1.31-2.el6.noarch                                                                     5/6 
  Installing : httpd-2.2.15-69.el6.centos.x86_64                                                               6/6 
  Verifying  : httpd-tools-2.2.15-69.el6.centos.x86_64                                                         1/6 
  Verifying  : httpd-2.2.15-69.el6.centos.x86_64                                                               2/6 
  Verifying  : apr-util-ldap-1.3.9-3.el6_0.1.x86_64                                                            3/6 
  Verifying  : apr-1.3.9-5.el6_9.1.x86_64                                                                      4/6 
  Verifying  : mailcap-2.1.31-2.el6.noarch                                                                     5/6 
  Verifying  : apr-util-1.3.9-3.el6_0.1.x86_64                                                                 6/6 

Installed:
  httpd.x86_64 0:2.2.15-69.el6.centos                                                                              

Dependency Installed:
  apr.x86_64 0:1.3.9-5.el6_9.1                           apr-util.x86_64 0:1.3.9-3.el6_0.1                        
  apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1                 httpd-tools.x86_64 0:2.2.15-69.el6.centos                
  mailcap.noarch 0:2.1.31-2.el6                         

Complete!

[aaa@qq.com ~]#service httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for centos6
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
                                                           [  OK  ]
[aaa@qq.com ~]#ss -ntl
State       Recv-Q Send-Q                         Local Address:Port                           Peer Address:Port 
LISTEN      0      128                                       :::80                                       :::*     
LISTEN      0      128                                       :::22                                       :::*     
LISTEN      0      128                                        *:22                                        *:*     
LISTEN      0      100                                      ::1:25                                       :::*     
LISTEN      0      100                                127.0.0.1:25                                        *:*     
[aaa@qq.com ~]#
[aaa@qq.com ~]#curl 192.168.32.6
[aaa@qq.com ~]#curl 127.0.0.1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
	<head>
		<title>Apache HTTP Server Test Page powered by CentOS</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<style type="text/css">
省略部分 httpd 返回的响应信息........

上面使用 yum 安装了默认的 httpd2.2.15 版本,并且成功启动,然后使用 web 服务器请求命令 curl 对本机的 httpd
发起请求,并且可以正常响应。通过上图我们知道该服务器的 IP 地址为 192.168.32.6, 我们也可以通过自己电脑中的浏览器给
httpd 发请求。

HTTPD ( apache ) WEB 服务器——HTTPD 安装

centos7 中安装HTTPD

相比 CentOS6 系统,CentOS7中默认的 httpd 版本为 2.4.6 版本。

[aaa@qq.com ~]#
[aaa@qq.com ~]#firewall-cmd --state
not running
[aaa@qq.com ~]#getenforce 
Disabled
[aaa@qq.com ~]#cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
[aaa@qq.com ~]#
[aaa@qq.com ~]#yum list http*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
http-parser.i686                                              2.7.1-8.el7                                   centos7
http-parser.x86_64                                            2.7.1-8.el7                                   centos7
http-parser-devel.i686                                        2.7.1-8.el7                                   centos7
http-parser-devel.x86_64                                      2.7.1-8.el7                                   centos7
httpcomponents-client.noarch                                  4.2.5-5.el7_0                                 centos7
httpcomponents-client-javadoc.noarch                          4.2.5-5.el7_0                                 centos7
httpcomponents-core.noarch                                    4.2.4-6.el7                                   centos7
httpcomponents-core-javadoc.noarch                            4.2.4-6.el7                                   centos7
httpcomponents-project.noarch                                 6-4.el7                                       centos7
httpd.x86_64                                                  2.4.6-90.el7.centos                           centos7
httpd-devel.x86_64                                            2.4.6-90.el7.centos                           centos7
httpd-itk.x86_64                                              2.4.7.04-2.el7                                epel   
httpd-manual.noarch                                           2.4.6-90.el7.centos                           centos7
httpd-tools.x86_64                                            2.4.6-90.el7.centos                           centos7
httping.x86_64                                                2.5-1.el7                                     epel   
httpress.x86_64                                               1.1.0-2.el7                                   epel   
httpry.x86_64                                                 0.1.8-1.el7                                   epel   
httpunit.noarch                                               1.7-15.el7                                    centos7
httpunit-doc.noarch                                           1.7-15.el7                                    centos7
httpunit-javadoc.noarch                                       1.7-15.el7                                    centos7
[aaa@qq.com ~]#
[aaa@qq.com ~]#rpm -qi htppd
package htppd is not installed
[aaa@qq.com ~]#
[aaa@qq.com ~]#
[aaa@qq.com ~]#yum install httpd -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
centos7                                                                                     | 3.6 kB  00:00:00     
epel                                                                                        | 5.3 kB  00:00:00     
(1/2): epel/updateinfo                                                                      | 1.0 MB  00:00:00     
(2/2): epel/primary_db                                                                      | 6.9 MB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-90.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-90.el7.centos for package: httpd-2.4.6-90.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-90.el7.centos.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-90.el7.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-90.el7.centos.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-5.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-90.el7.centos will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================
 Package                    Arch                  Version                             Repository              Size
===================================================================================================================
Installing:
 httpd                      x86_64                2.4.6-90.el7.centos                 centos7                2.7 M
Installing for dependencies:
 apr                        x86_64                1.4.8-5.el7                         centos7                103 k
 apr-util                   x86_64                1.5.2-6.el7                         centos7                 92 k
 httpd-tools                x86_64                2.4.6-90.el7.centos                 centos7                 91 k
 mailcap                    noarch                2.1.41-2.el7                        centos7                 31 k

Transaction Summary
===================================================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 3.0 M
Installed size: 10 M
Downloading packages:
(1/5): apr-1.4.8-5.el7.x86_64.rpm                                                           | 103 kB  00:00:00     
(2/5): apr-util-1.5.2-6.el7.x86_64.rpm                                                      |  92 kB  00:00:00     
(3/5): httpd-2.4.6-90.el7.centos.x86_64.rpm                                                 | 2.7 MB  00:00:00     
(4/5): mailcap-2.1.41-2.el7.noarch.rpm                                                      |  31 kB  00:00:00     
(5/5): httpd-tools-2.4.6-90.el7.centos.x86_64.rpm                                           |  91 kB  00:00:00     
-------------------------------------------------------------------------------------------------------------------
Total                                                                              7.6 MB/s | 3.0 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : apr-1.4.8-5.el7.x86_64                                                                          1/5 
  Installing : apr-util-1.5.2-6.el7.x86_64                                                                     2/5 
  Installing : httpd-tools-2.4.6-90.el7.centos.x86_64                                                          3/5 
  Installing : mailcap-2.1.41-2.el7.noarch                                                                     4/5 
  Installing : httpd-2.4.6-90.el7.centos.x86_64                                                                5/5 
  Verifying  : apr-1.4.8-5.el7.x86_64                                                                          1/5 
  Verifying  : mailcap-2.1.41-2.el7.noarch                                                                     2/5 
  Verifying  : httpd-tools-2.4.6-90.el7.centos.x86_64                                                          3/5 
  Verifying  : apr-util-1.5.2-6.el7.x86_64                                                                     4/5 
  Verifying  : httpd-2.4.6-90.el7.centos.x86_64                                                                5/5 

Installed:
  httpd.x86_64 0:2.4.6-90.el7.centos                                                                               

Dependency Installed:
  apr.x86_64 0:1.4.8-5.el7          apr-util.x86_64 0:1.5.2-6.el7     httpd-tools.x86_64 0:2.4.6-90.el7.centos    
  mailcap.noarch 0:2.1.41-2.el7    

Complete!
[aaa@qq.com ~]#
[aaa@qq.com ~]#
[aaa@qq.com ~]#ss -ntl
State       Recv-Q Send-Q            Local Address:Port                           Peer Address:Port              
LISTEN      0      128                           *:22                                        *:*                  
LISTEN      0      100                   127.0.0.1:25                                        *:*                  
LISTEN      0      128                          :::22                                       :::*                  
LISTEN      0      100                         ::1:25                                       :::*                  
[aaa@qq.com ~]#systemctl start httpd
[aaa@qq.com ~]#
[aaa@qq.com ~]#ss -ntl
State       Recv-Q Send-Q            Local Address:Port                           Peer Address:Port              
LISTEN      0      128                           *:22                                        *:*                  
LISTEN      0      100                   127.0.0.1:25                                        *:*                  
LISTEN      0      128                          :::80                                       :::*                  
LISTEN      0      128                          :::22                                       :::*                  
LISTEN      0      100                         ::1:25                                       :::*                  
[aaa@qq.com ~]#
[aaa@qq.com ~]#
[aaa@qq.com ~]#curl 192.168.32.7
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<title>Apache HTTP Server Test Page powered by CentOS</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <!-- Bootstrap -->
    <link href="/noindex/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="noindex/css/open-sans.css" type="text/css" />

<style type="text/css"><!--	
省略部分 httpd 响应信息.......

安装过程相对简单,依旧使用 curl 命令测试 httpd 是否正常启动,同理依旧可以使用自己电脑的浏览器测试 httpd 服务

HTTPD ( apache ) WEB 服务器——HTTPD 安装

centos6中编译安装httpd-2.4

由于 httpd 2.4 在 CentOS6 的仓库中默认没有,因此我们需要自己手动编译安装一个准备一台新安装的 CentOS6.X 服务器,关闭 selinux, 清空防火墙规则, 并安装编译依赖的软件包

编译安装文件下载官网

说明:安装httpd-2.4,依赖于apr-1.4+, apr-util-1.4+

部署环境:
Centos6.x

selinux为关闭状态,防火墙关闭状态

apache版本:httpd-2.4.39

apr版本:apr-1.7.0

apr-util版本:apr-util-1.6.1

源码包存放位置:~/

源码包编译安装位置:~/

[aaa@qq.com ~]#getenforce 
Disabled
[aaa@qq.com ~]#service iptables stop
[aaa@qq.com ~]#service iptables status
iptables: Firewall is not running.
[aaa@qq.com ~]#

#安装相关的工具包

[aaa@qq.com ~]# yum install gcc pcre-devel openssl-devel expat-devel autoconf libtool gcc-c++ -y
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package autoconf.noarch 0:2.63-5.1.el6 will be installed
---> Package expat-devel.x86_64 0:2.0.1-13.el6_8 will be installed
---> Package gcc.x86_64 0:4.4.7-23.el6 will be installed
--> Processing Dependency: libgomp = 4.4.7-23.el6 for package: gcc-4.4.7-23.el6.x86_64

中间部分省略......

Installed:
  autoconf.noarch 0:2.63-5.1.el6    expat-devel.x86_64 0:2.0.1-13.el6_8    gcc.x86_64 0:4.4.7-23.el6              
  gcc-c++.x86_64 0:4.4.7-23.el6     libtool.x86_64 0:2.2.6-15.5.el6        openssl-devel.x86_64 0:1.0.1e-57.el6   
  pcre-devel.x86_64 0:7.8-7.el6    

Dependency Installed:
  automake.noarch 0:1.11.1-4.el6                            cloog-ppl.x86_64 0:0.15.7-1.2.el6                      
  cpp.x86_64 0:4.4.7-23.el6                                 glibc-devel.x86_64 0:2.12-1.212.el6                    
  glibc-headers.x86_64 0:2.12-1.212.el6                     kernel-headers.x86_64 0:2.6.32-754.el6                 
  keyutils-libs-devel.x86_64 0:1.4-5.el6                    krb5-devel.x86_64 0:1.10.3-65.el6                      
  libcom_err-devel.x86_64 0:1.41.12-24.el6                  libgomp.x86_64 0:4.4.7-23.el6                          
  libkadm5.x86_64 0:1.10.3-65.el6                           libselinux-devel.x86_64 0:2.0.94-7.el6                 
  libsepol-devel.x86_64 0:2.0.41-4.el6                      libstdc++-devel.x86_64 0:4.4.7-23.el6                  
  mpfr.x86_64 0:2.4.1-6.el6                                 ppl.x86_64 0:0.10.2-11.el6                             
  zlib-devel.x86_64 0:1.2.3-29.el6                         

Complete!

下载对应的 httpd2.4.39 和 对应的 依赖的软件包源码

[aaa@qq.com ~]#yum install wget -y
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.12-10.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================
 Package                 Arch                      Version                        Repository                  Size
===================================================================================================================
Installing:
 wget                    x86_64                    1.12-10.el6                    centos6                    484 k

Transaction Summary
===================================================================================================================
Install       1 Package(s)

Total download size: 484 k
Installed size: 1.8 M
Downloading Packages:
wget-1.12-10.el6.x86_64.rpm                                                                 | 484 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : wget-1.12-10.el6.x86_64                                                                         1/1 
  Verifying  : wget-1.12-10.el6.x86_64                                                                         1/1 

Installed:
  wget.x86_64 0:1.12-10.el6                                                                                        

Complete!
[aaa@qq.com ~]#
[aaa@qq.com ~]#wget https://archive.apache.org/dist/httpd/httpd-2.4.39.tar.gz
--2019-12-09 15:31:46--  https://archive.apache.org/dist/httpd/httpd-2.4.39.tar.gz
Resolving archive.apache.org... 163.172.17.199
Connecting to archive.apache.org|163.172.17.199|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9199150 (8.8M) [application/x-gzip]
Saving to: “httpd-2.4.39.tar.gz”

100%[=========================================================================>] 9,199,150   30.8K/s   in 3m 27s  

2019-12-09 15:35:14 (43.3 KB/s) - “httpd-2.4.39.tar.gz” saved [9199150/9199150]

[aaa@qq.com ~]#wget https://www-us.apache.org/dist//apr/apr-1.7.0.tar.gz
--2019-12-09 15:37:43--  https://www-us.apache.org/dist//apr/apr-1.7.0.tar.gz
Resolving www-us.apache.org... 40.79.78.1
Connecting to www-us.apache.org|40.79.78.1|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1093896 (1.0M) [application/x-gzip]
Saving to: “apr-1.7.0.tar.gz.1”

100%[=========================================================================>] 1,093,896    236K/s   in 4.5s    

2019-12-09 15:37:48 (236 KB/s) - “apr-1.7.0.tar.gz.1” saved [1093896/1093896]

[aaa@qq.com ~]#wget https://www-us.apache.org/dist//apr/apr-util-1.6.1.tar.gz
--2019-12-09 19:17:46--  https://www-us.apache.org/dist//apr/apr-util-1.6.1.tar.gz
Resolving www-us.apache.org (www-us.apache.org)... 40.79.78.1
Connecting to www-us.apache.org (www-us.apache.org)|40.79.78.1|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 554301 (541K) [application/x-gzip]
Saving to: ‘apr-util-1.6.1.tar.gz’

100%[=========================================================================>] 554,301      215KB/s   in 2.5s   

2019-12-09 19:17:50 (215 KB/s) - ‘apr-util-1.6.1.tar.gz’ saved [554301/554301]

 

[aaa@qq.com ~]#ll -h
total 11M
-rw-------.  1 root root  957 Dec  9 15:08 anaconda-ks.cfg
-rw-r--r--   1 root root 1.1M Sep 21 23:46 apr-1.7.0.tar.gz
-rw-r--r--   1 root root 542K Sep 21 23:46 apr-util-1.6.1.tar.gz
-rw-r--r--   1 root root 8.8M Mar 31  2019 httpd-2.4.39.tar.gz
-rw-r--r--.  1 root root 9.3K Dec  9 15:08 install.log
-rw-r--r--.  1 root root 3.1K Dec  9 15:07 install.log.syslog


分别解压三个软件包, 执行编译安装过程,启动测试

[aaa@qq.com ~]#tar xvf httpd-2.4.39.tar.gz 

[aaa@qq.com ~]#tar xvf apr-1.7.0.tar.gz -C httpd-2.4.39/srclib/       #指定解压路径,解压到一起

[aaa@qq.com ~]#tar xf apr-util-1.6.1.tar.gz -C httpd-2.4.39/srclib/

[aaa@qq.com ~]#cd httpd-2.4.39/srclib/

[aaa@qq.com srclib]#ll
total 12
drwxr-xr-x 27 1001 1001 4096 Apr  2  2019 apr-1.7.0
drwxr-xr-x 20 1001 1001 4096 Oct 18  2017 apr-util-1.6.1
-rw-r--r--  1 root dip   121 Feb 11  2005 Makefile.in
[aaa@qq.com srclib]#
[aaa@qq.com srclib]#mv apr-1.7.0/ apr                #修改名称
[aaa@qq.com srclib]#mv apr-util-1.6.1/ apr-util
[aaa@qq.com srclib]#ll
total 12
drwxr-xr-x 27 1001 1001 4096 Apr  2  2019 apr
drwxr-xr-x 20 1001 1001 4096 Oct 18  2017 apr-util
-rw-r--r--  1 root dip   121 Feb 11  2005 Makefile.in

[aaa@qq.com srclib]#cd ../            #进到上级目录 httpd-2.4.39
[aaa@qq.com httpd-2.4.39]#
[aaa@qq.com httpd-2.4.39]#./configure --prefix=/usr/local/httpd24 --enable-so --enable-ssl 
--enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most 
--enable-mpms-shared=all --with-mpm=prefork

省略部分编译响应信息.......
config.status: creating support/phf_abuse_log.cgi
config.status: creating support/split-logfile
config.status: creating build/rules.mk
config.status: creating build/pkg/pkginfo
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands
configure: summary of build options:

    Server Version: 2.4.39
    Install prefix: /usr/local/httpd24
    C compiler:     gcc -std=gnu99
    CFLAGS:          -g -O2 -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E
[aaa@qq.com httpd-2.4.39]#
[aaa@qq.com httpd-2.4.39]#
[aaa@qq.com httpd-2.4.39]#make -j2;time  #双核编译   加个时间

省略部分编译响应信息.......
ttpd-2.4.39/modules/proxy -I/root/httpd-2.4.39/modules/http2 -I/root/httpd-2.4.39/modules/session -
I/root/httpd-2.4.39/modules/ssl -I/root/httpd-2.4.39/modules/test -I/root/httpd-2.4.39/server -
I/root/httpd-2.4.39/modules/md -I/root/httpd-2.4.39/modules/arch/unix -I/root/httpd-
2.4.39/modules/dav/main -I/root/httpd-2.4.39/modules/generators -I/root/httpd-2.4.39/modules/mappers 
-prefer-pic -c mod_rewrite.c && touch mod_rewrite.slo
/root/httpd-2.4.39/srclib/apr/libtool --silent --mode=link gcc -std=gnu99  -g -O2 -pthread          
 -o mod_vhost_alias.la -rpath /usr/local/httpd24/modules -module -avoid-version  mod_vhost_alias.lo 
/root/httpd-2.4.39/srclib/apr/libtool --silent --mode=link gcc -std=gnu99  -g -O2 -pthread           
-o mod_negotiation.la -rpath /usr/local/httpd24/modules -module -avoid-version  mod_negotiation.lo 
/root/httpd-2.4.39/srclib/apr/libtool --silent --mode=link gcc -std=gnu99  -g -O2 -pthread           
-o mod_dir.la -rpath /usr/local/httpd24/modules -module -avoid-version  mod_dir.lo 
/root/httpd-2.4.39/srclib/apr/libtool --silent --mode=link gcc -std=gnu99  -g -O2 -pthread          
 -o mod_actions.la -rpath /usr/local/httpd24/modules -module -avoid-version  mod_actions.lo 
/root/httpd-2.4.39/srclib/apr/libtool --silent --mode=link gcc -std=gnu99  -g -O2 -pthread          
 -o mod_speling.la -rpath /usr/local/httpd24/modules -module -avoid-version  mod_speling.lo 
/root/httpd-2.4.39/srclib/apr/libtool --silent --mode=link gcc -std=gnu99  -g -O2 -pthread          
 -o mod_userdir.la -rpath /usr/local/httpd24/modules -module -avoid-version  mod_userdir.lo 
/root/httpd-2.4.39/srclib/apr/libtool --silent --mode=link gcc -std=gnu99  -g -O2 -pthread          
 -o mod_alias.la -rpath /usr/local/httpd24/modules -module -avoid-version  mod_alias.lo 
/root/httpd-2.4.39/srclib/apr/libtool --silent --mode=link gcc -std=gnu99  -g -O2 -pthread          
 -o mod_rewrite.la -rpath /usr/local/httpd24/modules -module -avoid-version  mod_rewrite.lo 
make[4]: Leaving directory /root/httpd-2.4.39/modules/mappers'
make[3]: Leaving directory /root/httpd-2.4.39/modules/mappers'
make[2]: Leaving directory /root/httpd-2.4.39/modules'
make[2]: Entering directory /root/httpd-2.4.39/support'
make[2]: Leaving directory /root/httpd-2.4.39/support

make[1]: Leaving directory /root/httpd-2.4.39

real	0m0.000s
user	0m0.000s
sys	    0m0.000s
[aaa@qq.com httpd-2.4.39]#


[aaa@qq.com httpd-2.4.39]#make install


make[2]: Entering directory /root/httpd-2.4.39/support
make[2]: Leaving directory /root/httpd-2.4.39/support'

Installing configuration files
mkdir /usr/local/httpd24/conf
mkdir /usr/local/httpd24/conf/extra
mkdir /usr/local/httpd24/conf/original
mkdir /usr/local/httpd24/conf/original/extra
Installing HTML documents
mkdir /usr/local/httpd24/htdocs
Installing error documents
mkdir /usr/local/httpd24/error
Installing icons
mkdir /usr/local/httpd24/icons
mkdir /usr/local/httpd24/logs
Installing CGIs
mkdir /usr/local/httpd24/cgi-bin
Installing header files
Installing build system files
Installing man pages and online manual
mkdir /usr/local/httpd24/man
mkdir /usr/local/httpd24/man/man1
mkdir /usr/local/httpd24/man/man8
mkdir /usr/local/httpd24/manual
make[1]: Leaving directory /root/httpd-2.4.39

[aaa@qq.com httpd-2.4.39]
[aaa@qq.com httpd-2.4.39]
[aaa@qq.com httpd-2.4.39]#cd /usr/local/
[aaa@qq.com local]#ll
total 44
drwxr-xr-x.  2 root root 4096 Sep 23  2011 bin
drwxr-xr-x.  2 root root 4096 Sep 23  2011 etc
drwxr-xr-x.  2 root root 4096 Sep 23  2011 games
drwxr-xr-x  15 root root 4096 Dec  9 15:24 httpd24
drwxr-xr-x.  2 root root 4096 Sep 23  2011 include
drwxr-xr-x.  2 root root 4096 Sep 23  2011 lib
drwxr-xr-x.  2 root root 4096 Sep 23  2011 lib64
drwxr-xr-x.  2 root root 4096 Sep 23  2011 libexec
drwxr-xr-x.  2 root root 4096 Sep 23  2011 sbin
drwxr-xr-x.  5 root root 4096 Dec  9 15:07 share
drwxr-xr-x.  2 root root 4096 Sep 23  2011 src

[aaa@qq.com local]#cd httpd24/
[aaa@qq.com httpd24]#ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  lib  logs  man  manual  modules
[aaa@qq.com httpd24]#cd bin
[aaa@qq.com bin]#ll                 #服务命令列表
total 2508
-rwxr-xr-x 1 root root  136460 Dec  9 15:24 ab
-rwxr-xr-x 1 root dip     3437 Dec  9 15:22 apachectl
-rwxr-xr-x 1 root root    6959 Dec  9 15:24 apr-1-config
-rwxr-xr-x 1 root root    6149 Dec  9 15:24 apu-1-config
-rwxr-xr-x 1 root dip    23515 Dec  9 15:22 apxs
-rwxr-xr-x 1 root root   12221 Dec  9 15:24 checkgid
-rwxr-xr-x 1 root dip     8925 Dec  9 15:22 dbmmanage
-rw-r--r-- 1 root dip     1073 Dec  9 15:22 envvars
-rw-r--r-- 1 root dip     1073 Dec  9 15:22 envvars-std
-rwxr-xr-x 1 root root   20312 Dec  9 15:24 fcgistarter
-rwxr-xr-x 1 root root   66626 Dec  9 15:24 htcacheclean
-rwxr-xr-x 1 root root   40658 Dec  9 15:24 htdbm
-rwxr-xr-x 1 root root   22439 Dec  9 15:24 htdigest
-rwxr-xr-x 1 root root   41746 Dec  9 15:24 htpasswd
-rwxr-xr-x 1 root root 2064021 Dec  9 15:24 httpd
-rwxr-xr-x 1 root root   19448 Dec  9 15:24 httxt2dbm
-rwxr-xr-x 1 root root   22052 Dec  9 15:24 logresolve
-rwxr-xr-x 1 root root   37472 Dec  9 15:24 rotatelogs
[aaa@qq.com bin]#

[aaa@qq.com bin]#./apachectl start      #启动命令
AH00557: httpd: apr_sockaddr_info_get() failed for centos6
AH00558: httpd: Could not reliably determine the server s fully qualified domain name,
 using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
[aaa@qq.com bin]#ss -ntl
State       Recv-Q Send-Q                         Local Address:Port                           Peer Address:Port 
LISTEN      0      128                                       :::80                                       :::*     
LISTEN      0      128                                       :::22                                       :::*     
LISTEN      0      128                                        *:22                                        *:*     
LISTEN      0      100                                      ::1:25                                       :::*     
LISTEN      0      100                                127.0.0.1:25                                        *:*     
[aaa@qq.com bin]#curl 192.168.32.6
<html><body><h1>It works!</h1></body></html>
[aaa@qq.com bin]#
[aaa@qq.com bin]#cd ../
[aaa@qq.com httpd24]#ll
total 60
drwxr-xr-x  2 root root  4096 Dec  9 15:24 bin
drwxr-xr-x  2 root root  4096 Dec  9 15:24 build
drwxr-xr-x  2 root root  4096 Dec  9 15:24 cgi-bin
drwxr-xr-x  4 root root  4096 Dec  9 15:24 conf
drwxr-xr-x  3 root root  4096 Dec  9 15:24 error
drwxr-xr-x  2 root root  4096 Dec  9 15:24 htdocs
drwxr-xr-x  3 root root  4096 Dec  9 15:24 icons
drwxr-xr-x  2 root root  4096 Dec  9 15:24 include
drwxr-xr-x  3 root root  4096 Dec  9 15:24 lib
drwxr-xr-x  2 root root  4096 Dec  9 15:29 logs
drwxr-xr-x  4 root root  4096 Dec  9 15:24 man
drwxr-xr-x 14 root root 12288 Dec  9 15:24 manual
drwxr-xr-x  2 root root  4096 Dec  9 15:24 modules
[aaa@qq.com httpd24]#vim htdocs/index.html 
[aaa@qq.com httpd24]#cat htdocs/index.html
<html><body><h1>This is a cento6 test for httpd make install !</h1></body></html>

查看网页是否能够成功访问:
HTTPD ( apache ) WEB 服务器——HTTPD 安装
编译安装完成!

配置环境变量文件,并测试

[aaa@qq.com httpd24]#vim htdocs/index.html 

[aaa@qq.com httpd24]#cat htdocs/index.html
<html><body><h1>This is a cento6 test for httpd make install !</h1></body></html>

[aaa@qq.com httpd24]#vim /etc/profile.d/httpd24.sh

[aaa@qq.com httpd24]#cat /etc/profile.d/httpd24.sh
#!/bin/bash
#
#********************************************************************
#Author:		KAIVI
#Date:			2019-12-09
#FileName: 		/etc/profile.d/httpd24.sh
#Description:		The test script
#Copyright (C): 	2019 All rights reserved
#********************************************************************

export PATH=/usr/local/httpd24/bin:$PATH

[aaa@qq.com httpd24]#
[aaa@qq.com httpd24]#source /etc/profile.d/httpd24.sh
[aaa@qq.com httpd24]#
[aaa@qq.com httpd24]#cd
    
[aaa@qq.com ~]#apachectl stop
AH00557: httpd: apr_sockaddr_info_get() failed for centos6
AH00558: httpd: Could not reliably determine the server s fully qualified domain name, 
using 127.0.0.1. Set the 'ServerName directive globally to suppress this message
[aaa@qq.com ~]#ss -ntl
State       Recv-Q Send-Q                         Local Address:Port                           Peer Address:Port 
LISTEN      0      128                                       :::22                                       :::*     
LISTEN      0      128                                        *:22                                        *:*     
LISTEN      0      100                                      ::1:25                                       :::*     
LISTEN      0      100                                127.0.0.1:25                                        *:*     

[aaa@qq.com ~]#curl 127.0.0.1
curl: (7) couldn t connect to host

[aaa@qq.com ~]#apachectl start
AH00557: httpd: apr_sockaddr_info_get() failed for centos6
AH00558: httpd: Could not reliably determine the server s fully qualified domain name, 
using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
[aaa@qq.com ~]#curl 127.0.0.1
<html><body><h1>This is a cento6 test for httpd make install !</h1></body></html>
[aaa@qq.com ~]#
[aaa@qq.com ~]#ss -ntl
State       Recv-Q Send-Q                         Local Address:Port                           Peer Address:Port 
LISTEN      0      128                                       :::80                                       :::*     
LISTEN      0      128                                       :::22                                       :::*     
LISTEN      0      128                                        *:22                                        *:*     
LISTEN      0      100                                      ::1:25                                       :::*     
LISTEN      0      100                                127.0.0.1:25                                        *:*     
[aaa@qq.com ~]#

centos7中编译安装httpd-2.4

由于 httpd 2.4.41在 CentOS7的仓库中默认没有,因此需要自己手动编译安装一个准备一台新安装的 CentOS7.X 服务器,关闭 selinux, 清空防火墙规则, 并安装编译依赖的软件包

编译安装文件下载官网

说明:安装httpd-2.4,依赖于apr-1.4+, apr-util-1.4+

部署环境:
Centos7.x

selinux为关闭状态,防火墙关闭状态

apache版本:httpd-2.4.41

apr版本:apr-1.7.0

apr-util版本:apr-util-1.6.1

源码包存放位置:/usr/local/src/

源码包编译安装位置:~/app

新主机准备阶段:

[aaa@qq.com ~]#getenforce 
Disabled
[aaa@qq.com ~]#firewall-cmd --state
not running
[aaa@qq.com ~]#cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
[aaa@qq.com ~]#

#安装必要的工具包:

[aaa@qq.com ~]#yum -y install gcc make pcre-devel openssl-devel expat-devel

下载对应的 httpd2.4.41 和对应的依赖的软件包源码 ,按照习惯一般源码包放在/usr/local/src/下面

[aaa@qq.com ~]#cd  /usr/local/src/
[aaa@qq.com src]#
[aaa@qq.com src]#yum install wget -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
centos7                                                                            | 3.6 kB  00:00:00     
epel                                                                               | 5.3 kB  00:00:00     
(1/2): epel/updateinfo                                                             | 1.0 MB  00:00:00     
(2/2): epel/primary_db                                                             | 6.9 MB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.14-18.el7_6.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================
 Package             Arch                  Version                           Repository              Size
==========================================================================================================
Installing:
 wget                x86_64                1.14-18.el7_6.1                   centos7                547 k

Transaction Summary
==========================================================================================================
Install  1 Package

Total download size: 547 k
Installed size: 2.0 M
Downloading packages:
wget-1.14-18.el7_6.1.x86_64.rpm                                                    | 547 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : wget-1.14-18.el7_6.1.x86_64                                                            1/1 
  Verifying  : wget-1.14-18.el7_6.1.x86_64                                                            1/1 

Installed:
  wget.x86_64 0:1.14-18.el7_6.1                                                                           

Complete!
[aaa@qq.com src]#

下载对应的 httpd2.4.41 和对应的依赖的软件包源码

[aaa@qq.com src]#wget https://archive.apache.org/dist/httpd/httpd-2.4.41.tar.gz
--2019-12-09 18:03:52--  https://archive.apache.org/dist/httpd/httpd-2.4.41.tar.gz
Resolving archive.apache.org (archive.apache.org)... 163.172.17.199
Connecting to archive.apache.org (archive.apache.org)|163.172.17.199|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9267917 (8.8M) [application/x-gzip]
Saving to: ‘httpd-2.4.41.tar.gz’

100%[=========================================================================>] 9,267,917   53.2KB/s   in 1m 43s 

2019-12-09 18:05:38 (88.0 KB/s) - ‘httpd-2.4.41.tar.gz’ saved [9267917/9267917]

[aaa@qq.com src]#wget https://www-us.apache.org/dist//apr/apr-1.7.0.tar.gz
--2019-12-09 19:15:17--  https://www-us.apache.org/dist//apr/apr-1.7.0.tar.gz
Resolving www-us.apache.org (www-us.apache.org)... 40.79.78.1
Connecting to www-us.apache.org (www-us.apache.org)|40.79.78.1|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1093896 (1.0M) [application/x-gzip]
Saving to: ‘apr-1.7.0.tar.gz’

100%[=========================================================================>] 1,093,896    236KB/s   in 4.5s   

2019-12-09 19:15:30 (236 KB/s) - ‘apr-1.7.0.tar.gz’ saved [1093896/1093896]

[aaa@qq.com src]#wget https://www-us.apache.org/dist//apr/apr-util-1.6.1.tar.gz
--2019-12-09 19:17:46--  https://www-us.apache.org/dist//apr/apr-util-1.6.1.tar.gz
Resolving www-us.apache.org (www-us.apache.org)... 40.79.78.1
Connecting to www-us.apache.org (www-us.apache.org)|40.79.78.1|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 554301 (541K) [application/x-gzip]
Saving to: ‘apr-util-1.6.1.tar.gz’

100%[=========================================================================>] 554,301      215KB/s   in 2.5s   

2019-12-09 19:17:50 (215 KB/s) - ‘apr-util-1.6.1.tar.gz’ saved [554301/554301]
[aaa@qq.com src]#ll -h
total 11M
-rw-r--r-- 1 root root 1.1M Sep 21 23:46 apr-1.7.0.tar.gz
-rw-r--r-- 1 root root 542K Sep 21 23:46 apr-util-1.6.1.tar.gz
-rw-r--r-- 1 root root 8.9M Aug 13 07:37 httpd-2.4.41.tar.gz

解压下载好的压缩包

[aaa@qq.com src]#tar xvf httpd-2.4.41.tar.gz 

[aaa@qq.com src]#tar xvf apr-1.7.0.tar.gz 

[aaa@qq.com src]#tar xvf apr-util-1.6.1.tar.gz 

[aaa@qq.com src]#ll
total 10680
drwxr-xr-x 27 1001 1001    4096 Apr  2  2019 apr-1.7.0
-rw-r--r--  1 root root 1093896 Sep 21 23:46 apr-1.7.0.tar.gz
drwxr-xr-x 20 1001 1001    4096 Oct 18  2017 apr-util-1.6.1
-rw-r--r--  1 root root  554301 Sep 21 23:46 apr-util-1.6.1.tar.gz
drwxr-sr-x 11 root   40    4096 Aug  9 21:36 httpd-2.4.41
-rw-r--r--  1 root root 9267917 Aug 13 07:37 httpd-2.4.41.tar.gz

合并到httpd-2.4.41/srclib/文件夹中,并且改名为不带版本号的名称

[aaa@qq.com src]#ls httpd-2.4.41/srclib/
Makefile.in
[aaa@qq.com src]#mv apr-1.7.0 httpd-2.4.41/srclib/apr

[aaa@qq.com src]#mv apr-util-1.6.1 httpd-2.4.41/srclib/apr-util

[aaa@qq.com src]#cd httpd-2.4.41/srclib/

[aaa@qq.com srclib]#ll
total 12
drwxr-xr-x 27 1001 1001 4096 Apr  2  2019 apr
drwxr-xr-x 20 1001 1001 4096 Oct 18  2017 apr-util
-rw-r--r--  1 root   40  121 Feb 11  2005 Makefile.in

进到 httpd-2.4.41 文件夹里面,将三者一并编译并安装。

			 --prefix=/app/httpd24  软件安装位置
            --sysconf=/etc/httpd 配置文件位置
        --enable-so 支持模块化
        --enable-ssl 支持ssl功能
        --enable-cgi 支持cgi功能
        --enable-rewrite 支持url重写
        --enable-modules=most 启用模块级别:most大多数
        --enable-mpms-shared=all 支持所有支持的模块
        --with-mpm=prefork/event/worker mpm模块为prefork模式
        --with-zlib 支持传输压缩
        --with-pcre 支持pcre正则表达式
        --with-apr=/usr/local/apr apr位置为/usr/local/apr
        --with-apr-util=/usr/local/apr-util apr-util位置为/usr/local/apr
[aaa@qq.com srclib]#cd ../
[aaa@qq.com httpd-2.4.41]#./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-cgi 
--enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all 
--with-mpm=prefork 

[aaa@qq.com httpd-2.4.41]#make && make install

[aaa@qq.com httpd-2.4.41]#
[aaa@qq.com httpd-2.4.41]#cd /app/httpd24/
[aaa@qq.com httpd24]#ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  lib  logs  man  manual  modules
[aaa@qq.com httpd24]#cd bin
[aaa@qq.com bin]#ll
total 2712
-rwxr-xr-x 1 root root  160128 Dec  9 19:37 ab
-rwxr-xr-x 1 root   40    3419 Dec  9 19:35 apachectl        #启动命令
-rwxr-xr-x 1 root root    6952 Dec  9 19:37 apr-1-config
-rwxr-xr-x 1 root root    6149 Dec  9 19:37 apu-1-config
-rwxr-xr-x 1 root   40   23509 Dec  9 19:35 apxs
-rwxr-xr-x 1 root root   13152 Dec  9 19:37 checkgid
-rwxr-xr-x 1 root   40    8925 Dec  9 19:35 dbmmanage
-rw-r--r-- 1 root   40    1061 Dec  9 19:35 envvars
-rw-r--r-- 1 root   40    1061 Dec  9 19:35 envvars-std
-rwxr-xr-x 1 root root   23888 Dec  9 19:37 fcgistarter
-rwxr-xr-x 1 root root   79872 Dec  9 19:37 htcacheclean
-rwxr-xr-x 1 root root   47440 Dec  9 19:37 htdbm
-rwxr-xr-x 1 root root   25248 Dec  9 19:37 htdigest
-rwxr-xr-x 1 root root   49240 Dec  9 19:37 htpasswd
-rwxr-xr-x 1 root root 2191568 Dec  9 19:37 httpd
-rwxr-xr-x 1 root root   22064 Dec  9 19:37 httxt2dbm
-rwxr-xr-x 1 root root   25152 Dec  9 19:37 logresolve
-rwxr-xr-x 1 root root   43592 Dec  9 19:37 rotatelogs
[aaa@qq.com bin]#
[aaa@qq.com bin]#ss -ntl
State       Recv-Q Send-Q            Local Address:Port                           Peer Address:Port              
LISTEN      0      128                           *:22                                        *:*                  
LISTEN      0      100                   127.0.0.1:25                                        *:*                  
LISTEN      0      128                          :::22                                       :::*                  
LISTEN      0      100                         ::1:25                                       :::*                  
[aaa@qq.com bin]#./apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name,
 using fe80::20c:29ff:fe2e:a173%eth0. Set the 'ServerName' directive globally to suppress this message
[aaa@qq.com bin]#ss -ntl
State       Recv-Q Send-Q            Local Address:Port                           Peer Address:Port              
LISTEN      0      128                           *:22                                        *:*                  
LISTEN      0      100                   127.0.0.1:25                                        *:*                  
LISTEN      0      128                          :::80                                       :::*                  
LISTEN      0      128                          :::22                                       :::*                  
LISTEN      0      100                         ::1:25                                       :::*                  
[aaa@qq.com bin]#curl 192.168.32.7
<html><body><h1>It works!</h1></body></html>
[aaa@qq.com bin]#
[aaa@qq.com bin]#cd ../
[aaa@qq.com httpd24]#ll
total 44
drwxr-xr-x  2 root root  302 Dec  9 19:37 bin
drwxr-xr-x  2 root root  253 Dec  9 19:37 build
drwxr-xr-x  2 root root   78 Dec  9 19:37 cgi-bin
drwxr-xr-x  4 root root   84 Dec  9 19:37 conf
drwxr-xr-x  3 root root 4096 Dec  9 19:37 error
drwxr-xr-x  2 root root   24 Dec  9 19:37 htdocs
drwxr-xr-x  3 root root 8192 Dec  9 19:37 icons
drwxr-xr-x  2 root root 8192 Dec  9 19:37 include
drwxr-xr-x  3 root root  281 Dec  9 19:37 lib
drwxr-xr-x  2 root root   58 Dec  9 19:42 logs
drwxr-xr-x  4 root root   30 Dec  9 19:37 man
drwxr-xr-x 14 root root 8192 Dec  9 19:37 manual
drwxr-xr-x  2 root root 4096 Dec  9 19:37 modules
[aaa@qq.com httpd24]#vim htdocs/index.html 
[aaa@qq.com httpd24]#cat htdocs/index.html
<html><body><h1>hello kaivi,welcome to httpd Test !</h1></body></html>

查看网页是否能正常访问:
HTTPD ( apache ) WEB 服务器——HTTPD 安装
编译安装完成!

编译安装后配置

创建专用用户

[aaa@qq.com bin]#cd
[aaa@qq.com ~]#useradd -s /sbin/nologin -r apache
[aaa@qq.com ~]#

指定运行httpd的用户

[aaa@qq.com ~]#vim /app/httpd24/conf/httpd.conf 

#User daemon             #默认的用户
#Group daemon
User apache
Group apache

配置环境变量

[aaa@qq.com ~]#echo 'PATH=/app/httpd24/bin:$PATH' > /etc/profile.d/httpd24.sh
[aaa@qq.com ~]#. /etc/profile.d/httpd24.sh
[aaa@qq.com ~]#
[aaa@qq.com ~]#echo $PATH
/app/httpd24/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[aaa@qq.com ~]#
#修改一下访问页面内容:
[aaa@qq.com ~]#vim /app/httpd24/htdocs/index.html 

[aaa@qq.com ~]#cat /app/httpd24/htdocs/index.html
<html><body><h1> The home directory starts the HTTP test !</h1></body></html>
[aaa@qq.com ~]#

重新启动,这次直接在加目录中重新启动

[aaa@qq.com ~]#ss -ntl
State       Recv-Q Send-Q            Local Address:Port                           Peer Address:Port              
LISTEN      0      128                           *:22                                        *:*                  
LISTEN      0      100                   127.0.0.1:25                                        *:*                  
LISTEN      0      128                          :::22                                       :::*                  
LISTEN      0      100                         ::1:25                                       :::*                  
[aaa@qq.com ~]#apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, 
using fe80::20c:29ff:fe2e:a173%eth0. Set the 'ServerName' directive globally to suppress this message
[aaa@qq.com ~]#ss -ntl
State       Recv-Q Send-Q            Local Address:Port                           Peer Address:Port              
LISTEN      0      128                           *:22                                        *:*                  
LISTEN      0      100                   127.0.0.1:25                                        *:*                  
LISTEN      0      128                          :::80                                       :::*                  
LISTEN      0      128                          :::22                                       :::*                  
LISTEN      0      100                         ::1:25                                       :::*                  
[aaa@qq.com ~]#

查看网页是否能正常访问:
HTTPD ( apache ) WEB 服务器——HTTPD 安装
查看创建的用户是否加载成功:
HTTPD ( apache ) WEB 服务器——HTTPD 安装

设置开机启动

方法一:

设置开机启动,在这里还不是service文件,写service脚本文件比较繁琐。这里可以直接放到/etc/rc.d/rc.local 即可
但是需要注意执行权限的问题

[aaa@qq.com ~]#chmod +x /etc/rc.d/rc.local
[aaa@qq.com ~]#
[aaa@qq.com ~]#vim /etc/rc.d/rc.local

/app/httpd24/bin/apachectl start      #添加路径和命令 设置为开机自动启动


[aaa@qq.com ~]#reboot
[c:\~]$ 

Connecting to 192.168.32.7:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Mon Dec  9 20:06:59 2019 from 192.168.32.1
[aaa@qq.com ~]#
[aaa@qq.com ~]#ss -ntl
State       Recv-Q Send-Q            Local Address:Port                           Peer Address:Port              
LISTEN      0      128                           *:22                                        *:*                  
LISTEN      0      100                   127.0.0.1:25                                        *:*                  
LISTEN      0      128                          :::80                                       :::*                  
LISTEN      0      128                          :::22                                       :::*                  
LISTEN      0      100                         ::1:25                                       :::*                  
[aaa@qq.com ~]#

方法二:

设置开启启动可以配置对应的service文件

[aaa@qq.com ~]#vim /usr/lib/systemd/system/httpd.service

[aaa@qq.com ~]#cat /usr/lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=forking
#EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/app/httpd24/bin/httpd $OPTIONS -k start
ExecReload=/app/httpd24/bin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH {MAINPID}
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target

[aaa@qq.com ~]#
[aaa@qq.com ~]#systemctl daemon-reload   #重新加载服务

[aaa@qq.com ~]#systemctl status httpd    #查看状态
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:httpd(8)
           man:apachectl(8)
[aaa@qq.com ~]#ss -ntl
State       Recv-Q Send-Q            Local Address:Port                           Peer Address:Port              
LISTEN      0      128                           *:22                                        *:*                  
LISTEN      0      100                   127.0.0.1:25                                        *:*                  
LISTEN      0      128                          :::80                                       :::*                  
LISTEN      0      128                          :::22                                       :::*                  
LISTEN      0      100                         ::1:25                                       :::*                  
[aaa@qq.com ~]#apachectl stop   #关闭httpd服务
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using
 fe80::20c:29ff:fe2e:a173%eth0. Set the 'ServerName directive globally to suppress this message
[aaa@qq.com ~]#ss -ntl
State       Recv-Q Send-Q            Local Address:Port                           Peer Address:Port              
LISTEN      0      128                           *:22                                        *:*                  
LISTEN      0      100                   127.0.0.1:25                                        *:*                  
LISTEN      0      128                          :::22                                       :::*                  
LISTEN      0      100                         ::1:25                                       :::*                  
[aaa@qq.com ~]#systemctl start httpd   #用service服务启动
[aaa@qq.com ~]#ss -ntl
State       Recv-Q Send-Q            Local Address:Port                           Peer Address:Port              
LISTEN      0      128                           *:22                                        *:*                  
LISTEN      0      100                   127.0.0.1:25                                        *:*                  
LISTEN      0      128                          :::80                                       :::*                  
LISTEN      0      128                          :::22                                       :::*                  
LISTEN      0      100                         ::1:25                                       :::*                  
[aaa@qq.com ~]#
[aaa@qq.com ~]#systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-12-09 20:20:32 CST; 4min 25s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 15737 ExecStart=/app/httpd24/bin/httpd $OPTIONS -k start (code=exited, status=0/SUCCESS)
 Main PID: 15739 (httpd)
   CGroup: /system.slice/httpd.service
           ├─15739 /app/httpd24/bin/httpd -k start
           ├─15741 /app/httpd24/bin/httpd -k start
           ├─15742 /app/httpd24/bin/httpd -k start
           ├─15743 /app/httpd24/bin/httpd -k start
           ├─15744 /app/httpd24/bin/httpd -k start
           └─15745 /app/httpd24/bin/httpd -k start

Dec 09 20:20:27 centos7 systemd[1]: Starting The Apache HTTP Server...
Dec 09 20:20:32 centos7 httpd[15737]: AH00558: httpd: Could not reliably determine the server's fully quali...ssage
Dec 09 20:20:32 centos7 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

把之前/etc/rc.local文件中的开机自启文件给删除或者注释掉,试试用service启动


[aaa@qq.com ~]#vim /etc/rc.local

#/app/httpd24/bin/apachectl start              #注释掉

[aaa@qq.com ~]#systemctl enable httpd        #设置为开启启动
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[aaa@qq.com ~]#
[aaa@qq.com ~]#reboot
Connecting to 192.168.32.7:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Mon Dec  9 20:30:14 2019 from 192.168.32.1
[aaa@qq.com ~]#ss -ntl
State       Recv-Q Send-Q            Local Address:Port                           Peer Address:Port              
LISTEN      0      128                           *:22                                        *:*                  
LISTEN      0      100                   127.0.0.1:25                                        *:*                  
LISTEN      0      128                          :::80                                       :::*                  
LISTEN      0      128                          :::22                                       :::*                  
LISTEN      0      100                         ::1:25                                       :::*                  
[aaa@qq.com ~]#


扩展:创建启动脚本(CentOS 6 以前版本)

#自定义启动脚本(参考httpd-2.2的服务脚本)
cp /etc/rc.d/init.d/httpd /etc/rc.d/init.d/httpd24

[aaa@qq.com ~]vim /etc/rc.d/init.d/httpd24

apachectl=/app/httpd24/bin/apachectl
httpd=${HTTPD-/app/httpd24/bin/httpd}
pidfile=${PIDFILE-/app/httpd24/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}

[aaa@qq.com ~]chkconfig –add httpd24
[aaa@qq.com ~]chkconfig –list httpd24