编译安装httpd-2.4

准备工作

依赖关系

依赖于apr-1.4+, apr-util-1.4+, [apr-iconv]
  apr: apache portable runtime,解决跨平台实现
  CentOS 6:默认:apr-1.3.9, apr-util-1.3.9

APR

APR(Apache portable Run-time libraries,Apache可移植运行库) 主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。在早期的Apache版本中,应用程序本身必须能够处理各种具体操作系统平台的细节,并针对不同的平台调用不同的处理函数随着Apache的进一步开发,Apache组织决定将这些通用的函数独立出来并发展成为一个新的项目。这样,APR的开发就从Apache中独立出来,Apache仅仅是使用 APR而已。目前APR主要还是由Apache使用,由于APR的较好的移植性,因此一些需要进行移植的C程序也开始使用APR,开源项目比如用于服务器压力测试的Flood loader tester,该项目不仅仅适用于Apache,还应用于apache下的其他软件。

安装前准备开发包:

开发环境包:gcc,pcre-devel,openssl-devel,expat-devel
yum -y install  gcc pcre-devel openssl-devel expat-devel

下载源代码并解压缩:

httpd-2.4.46.tar.gz:地址http://httpd.apache.org/download.cgi
apr-1.7.0.tar.gz         地址https://apr.apache.org
apr-util-1.6.1.tar.gz    地址https://apr.apache.org

安装方法一

解压缩

上传文件至/app

解压缩:for i in `ll`;do tar -xzvf $i;done

安装apr-1.4+

cd /app/apr-1.7.0
./configure --prefix=/app/apr
make && make install

安装apr-util-1.4+

cd /app/apr-util-1.6.0
./configure --prefix=/app/apr-util --with-apr=/app/apr/
make -j 2 && make install

编译安装httpd-2.4

cd /app/httpd-2.4.46
./configure --prefix=/app/httpd24
--enable-so
--enable-ssl
--enable-cgi
--enable-rewrite
--with-zlib
--with-pcre
--with-apr=/app/apr/
--with-apr-util=/app/apr-util/
--enable-modules=most
--enable-mpms-shared=all
--with-mpm=prefork
make -j 4 && make install

安装方法二:

方法一中,httpd-2.4.46.tar.gz,apr-1.7.0.tar.gz,apr-util-1.6.1.tar.gz都是各自安装的,方法二将介绍一种整合的方法一次性安装三个包

cp -r apr-1.6.3 httpd-2.4.34/srclib/apr
cp -r apr-util-1.6.1 httpd-2.4.34/srclib/apr-util
cd httpd-2.4.34/
 ./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
make && make install

安装后的环境配置

Httpd编译过程:可通过此文件查看编译参数

  /app/httpd24/build/config.nice

自带的服务控制脚本:

  /app/httpd24/bin/apachectl

导出环境变量

vim /etc/profile.d/httpd24.sh
  export PATH=/app/httpd24/bin:$PATH
source /etc/profile.d/httpd24.sh

导出帮助手册

vim /etc/man.config
  MANPATH /app/httpd24/man

自定义启动脚本

/usr/lib/systemd/system/httpd24.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 #Type=notify #EnvironmentFile=/etc/sysconfig/httpd ExecStart=/app/httpd24/bin/httpd $OPTIONS -k start #ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND ExecReload=/app/httpd24/bin/httpd $OPTIONS -k graceful ExecStop=/bin/kill -WINCH ${MAINPID} # We want systemd to give httpd some time to finish gracefully, but still want # it to kill httpd after TimeoutStopSec if something went wrong during the # graceful stop. Normally, Systemd sends SIGTERM signal right after the # ExecStop, which would kill httpd. We are sending useless SIGCONT here to give # httpd time to finish. KillSignal=SIGCONT PrivateTmp=true [Install] WantedBy=multi-user.target

重载配置

systemctl daemon-reload

启动服务

systemctl start httpd24

原文地址:https://www.cnblogs.com/wxxjianchi/p/13547413.html