**编译说明和准备:**安装httpd-2.4,依赖于apr-1.4+, apr-util-1.4+
#安装相关包:
[root@centos7 ~]#yum -y install gcc make pcre-devel openssl-devel expat-devel`
#下载源代码并解压缩:
分别执行以下三条命令:
[root@centos7 ~]#wget https://downloads.apache.org/apr/apr-1.7.0.tar.bz2
[root@centos7 ~]#wget https://downloads.apache.org//apr/apr-util-1.6.1.tar.bz2
[root@centos7 ~]#wget https://downloads.apache.org//httpd/httpd-2.4.46.tar.bz2
执行ls查看 可以看到
[root@centos7 ~]#ll
total 10984
-rw-------. 1 root root 1371 Apr 8 08:46 anaconda-ks.cfg
-rw-r--r--. 1 root root 872238 Jul 6 2020 apr-1.7.0.tar.bz2
-rw-r--r--. 1 root root 428595 Jul 6 2020 apr-util-1.6.1.tar.bz2
-rw-r--r--. 1 root root 7187805 Aug 5 2020 httpd-2.4.46.tar.bz2
**编译安装httpd-2.4 **
1. 编译安装apr
(在编译安装之前,要先解压apr 执行命令,然后CD进入apr-1.7.0 再指定路径到/apps/apr 后安装,过程如下:
[root@centos7 ~]#tar xvf apr-1.7.0.tar.bz2
[root@centos7 ~]#cd apr-1.7.0
[root@centos7 apr-1.7.0]#./configure --prefix=/apps/apr
[root@centos7 apr-1.7.0]#make && make install
2. 编译安装apr-util
[root@centos7 ~]#tar xvf apr-util-1.6.1.tar.bz2
[root@centos7 ~]#cd ./apr-util-1.6.1/
[root@centos7 apr-util-1.6.1]#./configure --prefix=/apps/apr-util --with-apr=/apps/apr/
[root@centos7 apr-util-1.6.1]#make -j 2 && make install
3. 编译安装 httpd-2.4
[root@centos7 ~]#tar xvf httpd-2.4.46.tar.bz2
[root@centos7 ~]#cd ./httpd-2.4.46
[root@centos7 httpd-2.4.46]#./configure --prefix=/apps/httpd24 \ #这里后面跟换行符 表示后面还需要输入数据 输入后按回车
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=/apps/apr/ \
--with-apr-util=/apps/apr-util/ \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
[root@centos7 httpd-2.4.46]#make -j 4 && make install
安装结果如图
编译安装后配置
Httpd编译过程:/apps/httpd24/build/config.nice
自带的服务控制脚本:/apps/httpd24/bin/apachectl
1、创建专用用户
root@centos7 ~]#useradd -s /sbin/nologin -r apache
2、指定运行httpd的用户
[root@centos7 ~]#vim /apps/httpd24/conf/httpd
[root@centos7 ~]#cat /apps/httpd24/conf/httpd
user apache
group apache
3、配置环境变量
[root@centos7 ~]#echo 'PATH=/apps/httpd24/bin:$PATH' > /etc/profile.d/httpd.sh
. /etc/profile.d/httpd.sh
4、查看安装的版本:
5、配置帮助
[root@centos7 ~]#vim /etc/man_db.conf
6、设置开机自动启动
[root@centos7 ~]#vim /etc/rc.d/rc.local
/apps/httpd24/bin/apachectl start
[root@centos7 ~]#chmod +x /etc/rc.d/rc.local
创建service unit文件(CentOS 7 以上版本)
[root@centos7 ~]#cat /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
#EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/apps/httpd24/bin/apachectl start
#ExecStart=/apps/httpd24/bin/httpd $OPTIONS -k start
ExecReload=/apps/httpd24/bin/apachectl graceful
#ExecReload=/apps/httpd24/bin/httpd $OPTIONS -k graceful
ExecStop=/apps/httpd24/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
至此,安装完成