编译安装httpd2.4.46

httpd 包下载地址:http://httpd.apache.org/download.cgi

apr包下载地址:http://apr.apache.org/download.cgi

 selinux  firewalld  时间同步   把该干的都干了

首先安装需要的依赖包


[root@centos7 ~]#yum -y install gcc make pcre-devel openssl-devel expat-devel bzip2

以及需要的源码包3个

[root@centos7 src]# wget https://mirror.bit.edu.cn/apache//httpd/httpd-2.4.46.tar.bz2
[root@centos7 src]# wget https://mirrors.bfsu.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2
[root@centos7 src]# wget https://mirrors.bfsu.edu.cn/apache//apr/apr-1.7.0.tar.bz2

源码包解压

[root@centos7 src]# ls /usr/local/src
anaconda-ks.cfg  apr-1.7.0.tar.bz2  apr-util-1.6.1.tar.bz2  httpd-2.4.46.tar.bz2
[root@centos7 src]# tar -jxvf apr-1.7.0.tar.bz2 apr-util-1.6.1.tar.bz2 httpd-2.4.46.tar.bz2

三合一 一起编译

[root@centos7 src]# cd /usr/local/src/httpd-2.4.46
[root@centos7 src]# mv apr-1.7.0 httpd-2.4.46/srclib/apr
[root@centos7 src]# mv apr-util-1.6.1 httpd-2.4.46/srclib/apr-util 
[root@centos7 src]# ./configure 
--prefix=/apps/httpd 
--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
[root@centos7 src]#make && make install

 等着

Httpd编译过程:/app/httpd24/build/config.nice 自带的服务控制脚本:/app/httpd24/bin/apachectl
id apache查看账户存不存在  不存在就创建apache用户

[root@centos7 httpd-2.4.46]# useradd -s  /sbin/nologin -r apache

指定使用httpd的用户

[root@centos7 httpd-2.4.46]# vim /apps/httpd/conf/httpd
user apache
group apache

设置环境变量

[root@centos7 httpd-2.4.46]# vim /etc/profile.d/httpd.sh
PATH=/apps/httpd/bin:$PATH

man帮助路径

[root@centos7 httpd-2.4.46]# vim /etc/man_db.conf 
MANDATORY_MANPATH                       /apps/httpd/man

设置开机启动并增加执行权限

[root@centos7 httpd-2.4.46]# vim /etc/rc.d/rc.local 
/apps/httpd/bin/apachectl start
[root@centos7 httpd-2.4.46]# chmod +x /etc/rc.d/rc.local

创建service unit文件(CentOS 7 以上版本)

[root@centos7 httpd-2.4.46]# 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=/apps/httpd/bin/httpd $OPTIONS -k start
ExecReload=/apps/httpd/bin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH {MAINPID}
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target

启动时候报错了   嫌麻烦直接重启机器

看一下默认80端口是否打开   检查语法错误

[root@centos7 ~]# ss -ntl
State      Recv-Q Send-Q                    Local Address:Port                                   Peer Address:Port              
LISTEN     0      128                                   *:22                                                *:*                  
LISTEN     0      100                           127.0.0.1:25                                                *:*                  
LISTEN     0      128                                  :::80                                               :::*                  
LISTEN     0      128                                  :::22                                               :::*                  
LISTEN     0      100                                 ::1:25                                               :::*                  
[root@centos7 ~]# httpd -t
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using centos7.zty.org. Set the 'ServerName' directive globally to suppress this message
Syntax OK

改一下主机名再检查一遍

[root@centos7 ~]# vim /apps/httpd/conf/httpd.conf 
ServerName www.123.com:80
[root@centos7 ~]# httpd -t
Syntax OK

完成了

来源:https://www.cnblogs.com/zhangty333/p/13879138.html

原文地址:https://www.cnblogs.com/zhangty333/p/13879138.html