APR:Apache portable Run-time libraries,Apache可移植运行库,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。
环境准备:
CentOS7
安装包准备:
主程序包:httpd-2.4.46.tar.gz
依赖包:apr-1.7.0.tar.gz、apr-util-1.6.1.tar.gz
相关安装包
yum -y install gcc make pcre-devel openssl-devel expat-devel
解压安装包到/usr/local
tar xf apr-1.7.0.tar.gz -C /usr/local/
tar xf apr-util-1.6.1.tar.gz -C /usr/local/
tar xf httpd-2.4.46.tar.gz -C /usr/local/
将apr 和apr-util源码与httpd 源码合并
cd /usr/local/
mv apr-1.7.0/ httpd-2.4.46/srclib/apr
mv apr-util-1.6.1/ httpd-2.4.46/srclib/apr-util
[root@centos7 ~]#ll /usr/local/httpd-2.4.46/srclib/
total 16
drwxr-xr-x. 28 1001 1001 4096 Jan 22 09:31 apr
drwxr-xr-x. 21 1001 1001 4096 Jan 22 09:31 apr-util
-rw-r--r--. 1 root 40 121 Feb 11 2005 Makefile.in
将三者一并编译并安装
cd httpd-2.4.46
./configure \
--prefix=/app/httpd24 \ #设置安装位置
--enable-so \ #让apache核心装载DSO
--enable-ssl \ #开启SSL功能
--enable-cgi \ #实现CGI
--enable-rewrite \ #开启重读功能
--with-zlib \ #指定zlib压缩
--with-pcre \ #指定prec库
--with-included-apr \ #指定APR库
--enable-modules=most \ #开启绝大多数模块
--enable-mpms-shared=all \
--with-mpm=prefork #工作模式:prefork
make -j '可根据自己PC CPU内核按需设置,加快编译速度' && make install
创建专用用户
useradd -s /sbin/nologin -r apache
指定运行httpd的用户
vim /app/httpd24/conf/httpd
user apache
group apache
配置环境变量
echo 'PATH=/app/httpd24/bin:$PATH' > /etc/profile.d/http24.sh
. /etc/profile.d/http24.sh
创建service unit文件并设置开机启动
vim /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/apachectl start
#ExecStart=/app/httpd24/bin/httpd $OPTIONS -k start
ExecReload=/app/httpd24/bin/apachectl graceful
#ExecReload=/app/httpd24/bin/httpd $OPTIONS -k graceful
ExecStop=/app/httpd24/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl enable --now httpd
配置man帮助
vim /etc/man_db.conf
MANDATORY_MANPATH /app/httpd24/man