1. 基础环境准备
1.1 创建一个系统用户
[root@node2 ~]# useradd -r -M -s /sbin/nologin apache
[root@node2 ~]# id apache
uid=299(apache) gid=299(apache) groups=299(apache)
[root@node2 ~]#
1.2 所需工具安装:(wget、gcc、gcc-c++、make)
[root@node2 ~]# yum -y install gcc gcc-c++ make wget
1.3 下载源码包
httpd包下载地址:https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz
apr包下载地址:https://downloads.apache.org/apr/apr-1.7.0.tar.gz
apr-util包下载地址:https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
[root@node2 src]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz
[root@node2 src]# ls
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz debug httpd-2.4.54.tar.gz kernels
[root@node2 src]# tar xf apr-1.7.0.tar.gz
[root@node2 src]# tar xf apr-util-1.6.1.tar.gz
[root@node2 src]# tar xf httpd-2.4.54.tar.gz
[root@node2 src]# ls
apr-1.7.0 apr-util-1.6.1 debug httpd-2.4.54.tar.gz
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.54 kernels
[root@node2 src]#
1.4 其他环境所需准备:openssl-devel、pcre-devel、expat-devel、libtool
[root@node2 ~] yum -y install openssl-devel pcre-devel expat-devel libtool
2. apr编译安装
修改apr的configure脚本文件:删除或者注释 cfgfile"这行
2.1 指定安装路径configure
[root@node2 apr-1.7.0]# ./configure --prefix=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
Configuring APR library
...
configure: creating ./config.status
config.status: creating Makefile
config.status: creating include/apr.h
config.status: creating build/apr_rules.mk
config.status: creating build/pkg/pkginfo
config.status: creating apr-1-config
config.status: creating apr.pc
config.status: creating test/Makefile
config.status: creating test/internal/Makefile
config.status: creating include/arch/unix/apr_private.h
config.status: executing libtool commands
config.status: executing default commands
[root@node2 apr-1.7.0]#
2.2 检测通过后生产Makefile文件
[root@node2 apr-1.7.0]# ls
apr-1-config buildconf emacs-mode Makefile README
apr-config.in build-outputs.mk encoding Makefile.in README.cmake
apr.dep CHANGES file_io Makefile.win shmem
apr.dsp CMakeLists.txt helpers memory strings
apr.dsw config.layout include misc support
apr.mak config.log libapr.dep mmap tables
apr.pc config.nice libapr.dsp network_io test
apr.pc.in config.status libapr.mak NOTICE threadproc
apr.spec configure libapr.rc NWGNUmakefile time
atomic configure.in libtool passwd tools
build docs LICENSE poll user
build.conf dso locks random
[root@node2 apr-1.7.0]#
2.3 执行make命令进行编译
[root@node2 apr-1.7.0]# make -j 2
...
serinfo.lo -lrt -lcrypt -lpthread -ldl
make[1]: Leaving directory '/usr/src/apr-1.7.0'
[root@node2 apr-1.7.0]#
2.4 执行make install命令
[root@node2 apr-1.7.0]# make install
...
done
/usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk
/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config
[root@node2 apr-1.7.0]#
3. apr-util编译安装
3.1 指定安装路径configure
[root@node2 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
...
configure: creating ./config.status
config.status: creating Makefile
config.status: creating export_vars.sh
config.status: creating build/pkg/pkginfo
config.status: creating apr-util.pc
config.status: creating apu-1-config
config.status: creating include/private/apu_select_dbm.h
config.status: creating include/apr_ldap.h
config.status: creating include/apu.h
config.status: creating include/apu_want.h
config.status: creating test/Makefile
config.status: creating include/private/apu_config.h
config.status: executing default commands
[root@node2 apr-util-1.6.1]#
3.2 检测通过后生产Makefile文件
[root@node2 apr-util-1.6.1]# ls
aprutil.dep CHANGES export_vars.sh.in NOTICE
aprutil.dsp CMakeLists.txt hooks NWGNUmakefile
aprutil.dsw config.layout include README
aprutil.mak config.log ldap README.cmake
apr-util.pc config.nice libaprutil.dep README.FREETDS
apr-util.pc.in config.status libaprutil.dsp redis
apr-util.spec configure libaprutil.mak renames_pending
apu-1-config configure.in libaprutil.rc strmatch
apu-config.in crypto LICENSE test
buckets dbd Makefile uri
build dbm Makefile.in xlate
build.conf docs Makefile.win xml
buildconf encoding memcache
build-outputs.mk export_vars.sh misc
[root@node2 apr-util-1.6.1]#
3.3 执行make命令进行编译
[root@node2 apr-util-1.6.1]# make -j 2
...
export_vars.c | sed -e 's/^\#[^!]*//' | sed -e '/^$/d' >> aprutil.exp
sed 's,^\(location=\).*$,\1installed,' < apu-1-config > apu-config.out
make[1]: Leaving directory '/usr/src/apr-util-1.6.1'
[root@node2 apr-util-1.6.1]#
3.4 执行make install命令
[root@node2 apr-util-1.6.1]# make install
...
----------------------------------------------------------------------
/usr/bin/install -c -m 644 aprutil.exp /usr/local/apr-util/lib
/usr/bin/install -c -m 755 apu-config.out /usr/local/apr-util/bin/apu-1-config
[root@node2 apr-util-1.6.1]#
4.httpd编译安装
4.1 指定安装路径configure
[root@node2 httpd-2.4.54]# ./configure --prefix=/usr/local/apache \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util/ \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
...
Server Version: 2.4.54
Install prefix: /usr/local/apache
C compiler: gcc
CFLAGS: -g -O2 -pthread
CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
LDFLAGS:
LIBS:
C preprocessor: gcc -E
[root@node2 httpd-2.4.54]#
4.2 检测通过后生产Makefile文件
[root@node2 httpd-2.4.54]# ls
ABOUT_APACHE changes-entries httpd.dsp Makefile README.platforms
acinclude.m4 CMakeLists.txt httpd.mak Makefile.in ROADMAP
Apache-apr2.dsw config.layout httpd.spec Makefile.win server
Apache.dsw config.log include modules srclib
apache_probes.d config.nice INSTALL modules.c support
ap.d config.status InstallBin.dsp NOTICE test
build configure LAYOUT NWGNUmakefile VERSIONING
BuildAll.dsp configure.in libhttpd.dep os
BuildBin.dsp docs libhttpd.dsp README
buildconf emacs-style libhttpd.mak README.CHANGES
CHANGES httpd.dep LICENSE README.cmake
[root@node2 httpd-2.4.54]#
4.3 执行make命令进行编译
[root@node2 httpd-2.4.54]# make
...
make[4]: Leaving directory '/usr/src/httpd-2.4.54/modules/mappers'
make[3]: Leaving directory '/usr/src/httpd-2.4.54/modules/mappers'
make[2]: Leaving directory '/usr/src/httpd-2.4.54/modules'
make[2]: Entering directory '/usr/src/httpd-2.4.54/support'
make[2]: Leaving directory '/usr/src/httpd-2.4.54/support'
make[1]: Leaving directory '/usr/src/httpd-2.4.54'
4.4 执行make intall命令
[root@node2 httpd-2.4.54]# make install
mkdir /usr/local/apache/man
mkdir /usr/local/apache/man/man1
mkdir /usr/local/apache/man/man8
mkdir /usr/local/apache/manual
make[1]: Leaving directory '/usr/src/httpd-2.4.54'
[root@node2 httpd-2.4.54]#
4.5 设置环境变量
[root@node2 local]# ls
apache apr-util etc include lib64 sbin src
apr bin games lib libexec share
[root@node2 local]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh
[root@node2 local]# source /etc/profile.d/apache.sh
[root@node2 local]# which httpd
/usr/local/apache/bin/httpd
[root@node2 local]#
4.6 设置映射关系
[root@node2 ~]# ls /usr/local/apache/
bin cgi-bin error icons logs manual
build conf htdocs include man modules
[root@mashuangle ~]# ln -s /usr/local/apache/include/ /usr/include/apache
[root@node2 ~]#
4.7 设置man文档
[root@node2 ~]# vi /etc/man_db.conf
#
#MANDATORY_MANPATH /usr/src/pvm3/man
#
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/apache/man
5. 开启httpd服务
[root@node2 ~]# apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fe87:473b%ens160. Set the 'ServerName' directive globally to suppress this message
[root@node2 ~]#
6. 关闭防火墙和selinux并查看端口号
[root@node2 ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@node2 ~]# vim /etc/selinux/config
修改
SELINUX=disabled
[root@node2 ~]# setenforce 0
[root@node2 ~]# getenforce
Permissive
[root@node2 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 64 [::]:45837 [::]:* LISTEN 0 128 [::]:111 [::]:* LISTEN 0 128 *:80 *:*
7. 使用地址访问
8. 源码编译报错信息处理总结
xml/apr_xml.c:35:10: fatal error: expat.h: No such file or directory #include <expat.h> ^~~ 解决方案
[root@node2 apr-util-1.6.1]# yum install -y expat-devel
configure: error: pcre(2)-config for libpcre not found. PCRE is required and available from http://pcre.org/ 解决方案
[root@node2 httpd-2.4.54]# yum -y install pcre-devel
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures 解决方案
[root@node2 httpd-2.4.54]# yum -y install openssl-devel
collect2: error: ld returned 1 exit status 解决方案
[root@node2 ~]# yum install -y libxml2-devel标签:httpd,apr,config,编译,源码,usr,node2,root From: https://www.cnblogs.com/msl1105/p/17004551.html
[root@node2 ~]#rm -rf /usr/local/apr-util
[root@node2 src]# rm -rf apr-util-1.6.1
[root@node2 src]# ls
apr-1.7.0 apr-util-1.6.1.tar.gz httpd-2.4.54 kernels
apr-1.7.0.tar.gz debug httpd-2.4.54.tar.gz
[root@node2 src]# tar xf apr-util-1.6.1.tar.gz
[root@node2 src]# cd apr-util-1.6.1
[root@node2 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@node2 apr-util-1.6.1]#make && make install
[root@node2 apr-util-1.6.1]# cd
[root@node2 ~]# cd /usr/src/httpd-2.4.54
[root@node2 httpd-2.4.54]# [root@node2 httpd-2.4.54]# ./configure --prefix=/usr/local/apache \
> --enable-so \
> --enable-ssl \
> --enable-cgi \
> --enable-rewrite \
> --with-zlib \
> --with-pcre \
> --with-apr=/usr/local/apr \
h-mpm=prefork> --with-apr-util=/usr/local/apr-util/ \
> --enable-modules=most \
> --enable-mpms-shared=all \
> --with-mpm=prefork