源码包安装apache

用源码包安装apache

以下是一步一步安装时可能会遇到的错误及解决的方式

//下载源码包
[root@localhost ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.46.tar.bz2
[root@localhost ~]# ls
anaconda-ks.cfg  httpd-2.4.46.tar.bz2

//解压并进入
[root@localhost ~]# tar xf httpd-2.4.46.tar.bz2 
[root@localhost ~]# ls
anaconda-ks.cfg  httpd-2.4.46  httpd-2.4.46.tar.bz2
[root@localhost ~]# cd httpd-2.4.46
[root@localhost httpd-2.4.46]# ls
ABOUT_APACHE     BuildBin.dsp    emacs-style     LAYOUT        NOTICE            srclib
acinclude.m4     buildconf       httpd.dep       libhttpd.dep  NWGNUmakefile     support
Apache-apr2.dsw  CHANGES         httpd.dsp       libhttpd.dsp  os                test
Apache.dsw       CMakeLists.txt  httpd.mak       libhttpd.mak  README            VERSIONING
apache_probes.d  config.layout   httpd.spec      LICENSE       README.cmake
ap.d             configure       include         Makefile.in   README.platforms
build            configure.in    INSTALL         Makefile.win  ROADMAP
BuildAll.dsp     docs            InstallBin.dsp  modules       server

//尝试安装apache
[root@localhost httpd-2.4.46]# ./configure --prefix=/usr/local/httpd
checking for APR... no
configure: error: APR not found.  Please read the documentation.

//解决apr not found问题
[root@localhost httpd-2.4.46]# cd
[root@localhost ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz
[root@localhost ~]# tar xf apr-1.7.0.tar.gz 
[root@localhost ~]# cd apr-1.7.0
[root@localhost apr-1.7.0]# ls
apr-config.in  build.conf        dso         libapr.rc     NOTICE         support
apr.dep        buildconf         emacs-mode  LICENSE       NWGNUmakefile  tables
apr.dsp        build-outputs.mk  encoding    locks         passwd         test
apr.dsw        CHANGES           file_io     Makefile.in   poll           threadproc
apr.mak        CMakeLists.txt    helpers     Makefile.win  random         time
apr.pc.in      config.layout     include     memory        README         tools
apr.spec       configure         libapr.dep  misc          README.cmake   user
atomic         configure.in      libapr.dsp  mmap          shmem
build          docs              libapr.mak  network_io    strings
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# echo $?
0
[root@localhost apr-1.7.0]# make
[root@localhost apr-1.7.0]# echo $?
0
[root@localhost apr-1.7.0]# make install
[root@localhost apr-1.7.0]# echo $?
0

//再尝试安装apache
[root@localhost apr-1.7.0]# cd
[root@localhost ~]# cd httpd-2.4.46
[root@localhost httpd-2.4.46]# ./configure --prefix=/usr/local/httpd
checking for APR-util... no
configure: error: APR-util not found.  Please read the documentation.

//解决APR-util not found问题
[root@localhost httpd-2.4.46]# cd
[root@localhost apr-util-1.6.1]# wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
[root@localhost ~]# tar xf apr-util-1.6.1.tar.gz 
[root@localhost ~]# cd apr-util-1.6.1
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util
configure: error: APR could not be located. Please use the --with-apr option.

//解决APR could not be located问题
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# make
xml/apr_xml.c:35:10: fatal error: expat.h: No such file or directory

//解决缺少expat库问题
[root@localhost apr-util-1.6.1]# yum -y install expat-devel
[root@localhost apr-util-1.6.1]# echo $?
[root@localhost apr-util-1.6.1]# 0
[root@localhost apr-util-1.6.1]# make install
[root@localhost apr-util-1.6.1]# echo $?
[root@localhost apr-util-1.6.1]# 0

//再尝试安装apache
[root@localhost apr-util-1.6.1]# cd
[root@localhost ~]# cd httpd-2.4.46
[root@localhost httpd-2.4.46]# ./configure --prefix=/usr/local/httpd
checking for APR-util... no
configure: error: APR-util not found.  Please read the documentation.

//解决APR-util还是not found问题
[root@localhost httpd-2.4.46]# ./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
configure: summary of build options:
    Server Version: 2.4.46
    Install prefix: /usr/local/httpd
    C compiler:     gcc
    CFLAGS:          -g -O2 -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E
[root@localhost httpd-2.4.46]# echo $?
0
[root@localhost httpd-2.4.46]# make
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:48: htpasswd] Error 1
make[2]: Leaving directory '/root/httpd-2.4.46/support'
make[1]: *** [/root/httpd-2.4.46/build/rules.mk:75: all-recursive] Error 1
make[1]: Leaving directory '/root/httpd-2.4.46/support'
make: *** [/root/httpd-2.4.46/build/rules.mk:75: all-recursive] Error 1
[root@localhost httpd-2.4.46]# echo $?
2

//缺少了xml相关的库,需要安装libxml2-devel包。直接安装并不能解决问题,因为httpd调用的apr-util已经安装好了,但是apr-util并没有libxml2-devel包支持。
//安装libxml2-devel包
[root@localhost httpd-2.4.46]# yum -y install libxml2-devel

//删除apr-util安装目录,并重新编译安装
[root@localhost httpd-2.4.46]# rm -rf /usr/local/apr-util/
[root@localhost httpd-2.4.46]# cd
[root@localhost ~]# cd apr-util-1.6.1

//清除之前配置时的缓存
[root@localhost apr-util-1.6.1]# make clean

//重新安装apr-util
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# echo $?
0
[root@localhost apr-util-1.6.1]# make
[root@localhost apr-util-1.6.1]# echo $?
0
[root@localhost apr-util-1.6.1]# make install
[root@localhost apr-util-1.6.1]# echo $?
0

//重新编译安装httpd
[root@localhost apr-util-1.6.1]# cd
[root@localhost ~]# cd httpd-2.4.46
[root@localhost httpd-2.4.46]# make clean
[root@localhost httpd-2.4.46]# ./configure --prefix=/usr/local/httpd  --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
configure: summary of build options:
    Server Version: 2.4.46
    Install prefix: /usr/local/httpd
    C compiler:     gcc
    CFLAGS:          -g -O2 -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E
[root@localhost httpd-2.4.46]# echo $?
0
[root@localhost httpd-2.4.46]# make
[root@localhost httpd-2.4.46]# echo $?
0
[root@localhost httpd-2.4.46]# make install
[root@localhost httpd-2.4.46]# echo $?
0

//关闭防火墙修改配置文件并重启服务
[root@localhost httpd-2.4.46]# systemctl stop firewalld
[root@localhost httpd-2.4.46]# getenforce 
Enforcing
[root@localhost httpd-2.4.46]# setenforce 0
[root@localhost httpd-2.4.46]# getenforce 
Permissive
[root@localhost httpd-2.4.46]# /usr/local/httpd/bin/apachectl start
[root@localhost httpd-2.4.46]# vi /usr/local/httpd/conf/httpd.conf 
ServerName localhost:80
[root@localhost httpd-2.4.46]# /usr/local/httpd/bin/apachectl restart

//修改环境变量
[root@localhost httpd-2.4.46]# cd
[root@localhost ~]# vi /etc/profile.d/apache.sh
export PATH=$PATH:/usr/local/httpd/bin/
[root@localhost ~]# source /etc/profile.d/apache.sh

//设置头文件链接(映射include路径)
[root@localhost ~]# ln -s /usr/local/httpd/include/ /usr/include/httpd

//添加man路径
[root@localhost man]# vi /etc/man_db.conf
MANDATORY_MANPATH                       /usr/local/httpd/man
MANDATORY_MANPATH                       /usr/local/httpd/manual

//测试apache服务
[root@localhost man]# cd
[root@localhost ~]# apachectl stop
[root@localhost ~]# ss -antl
State       Recv-Q      Send-Q           Local Address:Port             Peer Address:Port 
LISTEN      0           128                    0.0.0.0:22                    0.0.0.0:*   
LISTEN      0           128                       [::]:22                       [::]:*   
[root@localhost ~]# apachectl start
[root@localhost ~]# ss -antl
State       Recv-Q      Send-Q           Local Address:Port             Peer Address:Port 
LISTEN      0           128                    0.0.0.0:22                    0.0.0.0:*   
LISTEN      0           128                          *:80                          *:*   
LISTEN      0           128                       [::]:22                       [::]:*  
[root@localhost ~]# ip a
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:f9:ec:35 brd ff:ff:ff:ff:ff:ff
    inet 192.168.237.128/24 brd 192.168.237.255 scope global dynamic noprefixroute ens160
       valid_lft 1649sec preferred_lft 1649sec
    inet6 fe80::96da:6b44:5ce1:8588/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

测试成功

源码包安装apache

上一篇:【CTF】10个经典的CTF-web题目学习


下一篇:Error:(4,46) 程序包org.springframwork.boot.autoconfigure不存在