实验环境:
[root@Centos7 data]# uname -r
3.10.0-693.el7.x86_64
[root@Centos7 data]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core)
[root@Centos7 data]# ls
httpd-2.4.25.tar.bz2查看本机是否有安装httpd,如有请卸载
[root@Centos7 data]# rpm -q httpd
package httpd is not installed源码编译安装httpd之前,先使用yum安装相关依赖包
[root@Centos7 data]# yum -y install gcc openssl-devel pcre-devel apr-devel apr-util-devel创建一个目录专门用于管理源码编译的程序/apps
[root@Centos7 data]# mkdir /apps解包httpd-2.4.25.tar.bz2
[root@Centos7 data]# tar xf httpd-2.4.25.tar.bz2 
[root@Centos7 data]# ls
httpd-2.4.25  httpd-2.4.25.tar.bz2
[root@Centos7 data]# cd httpd-2.4.25/
[root@Centos7 httpd-2.4.25]# ls
ABOUT_APACHE     BuildAll.dsp    configure.in  include         LICENSE        README            test
acinclude.m4     BuildBin.dsp    docs          INSTALL         Makefile.in    README.cmake      VERSIONING
Apache-apr2.dsw  buildconf       emacs-style   InstallBin.dsp  Makefile.win   README.platforms
Apache.dsw       CHANGES         httpd.dep     LAYOUT          modules        ROADMAP
apache_probes.d  CMakeLists.txt  httpd.dsp     libhttpd.dep    NOTICE         server
ap.d             config.layout   httpd.mak     libhttpd.dsp    NWGNUmakefile  srclib
build            configure       httpd.spec    libhttpd.mak    os             support通过查看INSTALL文件,就基本能知道该如何去编译安装httpd
由于是简易的源码编译安装httpd,所以只需要指定一些简单的选项即可
编译安装三大步:
1、./configure
2、make
3、make install
[root@Centos7 httpd-2.4.25]# ./configure > --prefix=/apps/httpd24 \          #安装路径
> --sysconfdir=/etc/httpd \         #配置文件路径
> --enable-ssl \                          #启动ssl加密功能
> --enable-so                             #启动共享库
configure: summary of build options:
    Server Version: 2.4.25
    Install prefix: /apps/httpd24
    C compiler:     gcc -std=gnu99
    CFLAGS:           -pthread
    LDFLAGS:         
    LIBS:           
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE
    C preprocessor: gcc -E
[root@Centos7 httpd-2.4.25]# make && make install
...
Installing man pages and online manual
mkdir /apps/httpd24/man
mkdir /apps/httpd24/man/man1
mkdir /apps/httpd24/man/man8
mkdir /apps/httpd24/manual
make[1]: Leaving directory `/data/httpd-2.4.25‘设定PATH路径
[root@Centos7 httpd-2.4.25]# cd /apps/
[root@Centos7 apps]# ls
httpd24
[root@Centos7 apps]# ls httpd24/bin/
ab         apxs      dbmmanage  envvars-std  htcacheclean  htdigest  httpd      logresolve
apachectl  checkgid  envvars    fcgistarter  htdbm         htpasswd  httxt2dbm  rotatelogs
[root@Centos7 apps]# cd httpd24/bin/
[root@Centos7 bin]# pwd
/apps/httpd24/bin
[root@Centos7 bin]# echo "PATH=/apps/httpd24/bin:$PATH" > /etc/profile.d/httpd.sh
[root@Centos7 bin]# . /etc/profile.d/httpd.sh启动httpd24服务,访问主页
[root@Centos7 bin]# cd
[root@Centos7 ~]# apachectl start
AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using Centos7.localdomain. Set the ‘ServerName‘ directive globally to suppress this message
[root@Centos7 ~]# ss -tn
State      Recv-Q Send-Q            Local Address:Port                           Peer Address:Port              
ESTAB      0      0                    10.0.17.93:22                               10.0.16.89:49385              
[root@Centos7 ~]# ss -tnl
State      Recv-Q Send-Q            Local Address:Port                           Peer Address:Port              
LISTEN     0      128                           *:111                                       *:*                  
LISTEN     0      5                 192.168.122.1:53                                        *:*                  
LISTEN     0      128                           *:22                                        *:*                  
LISTEN     0      128                   127.0.0.1:631                                       *:*                  
LISTEN     0      100                   127.0.0.1:25                                        *:*                  
LISTEN     0      128                          :::111                                      :::*                  
LISTEN     0      128                          :::80                                       :::*                  
LISTEN     0      128                          :::22                                       :::*                  
LISTEN     0      128                         ::1:631                                      :::*                  
LISTEN     0      100                         ::1:25                                       :::*                  
[root@Centos7 ~]# curl http://localhost
<html><body><h1>It works!</h1></body></html>如果想开机启动,可以把apachectl start写入到/etc/rc.local 文件里
原文:https://blog.51cto.com/14812296/2511178