apache编译安装

概述

因为安全漏洞,原有nagios需要升级httpd版本至 2.4.62,记录如下:

参考

链接: httpd官方文档
链接: httpd官方文档-安装

环境

操作系统

  • CentOS 7

其他软件

  • php5
  • nagios 4.2.1

安装

下载软件包

  1. 下载APR and APR-Util(https://httpd.apache.org/docs/2.4/install.html)
    • wget https://dlcdn.apache.org//apr/apr-1.7.4.tar.gz
    • wget https://dlcdn.apache.org//apr/apr-util-1.6.3.tar.gz
  2. 下载PCRE(https://sourceforge.net/projects/pcre/)
    • wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.zip
  3. 下载httpd(https://httpd.apache.org/download.cgi#apache24)
    • wget https://dlcdn.apache.org/httpd/httpd-2.4.62.tar.gz

准备编译环境

yum install -y gcc gcc-c++ openssh-clients openssl-devel unzip

编译安装

  1. 安装apr
tar -zxvf apr-1.7.4.tar.gz && cd apr-1.7.4
./configure
make && make install
  1. 安装apr-util
tar -zxvf apr-util-1.6.3.tar.gz && cd apr-util-1.6.3
./configure --with-apr=/usr/local/apr
make && make install
  1. 安装pcre
unzip  pcre-8.45.zip && cd pcre-8.45
./configure
make && make install
  1. 安装httpd
    详见 httpd官方文档 - 多处理模块(MPM)
tar -zxvf httpd-2.4.62.tar.gz && cd httpd-2.4.62
# 为了兼容旧php5使用了prefork,默认是event
# 默认安装路径 /usr/local/apache2
./configure --with-mpm=prefork
make && make install

安装检查

# 检查安装路径
[root@localhost public]# cd /usr/local/apache2/
[root@localhost apache2]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules
# 检查安装版本信息
[root@localhost apache2]# bin/httpd -v
Server version: Apache/2.4.62 (Unix)
Server built:   Jul 30 2024 09:18:11
# 检查当前运行模块(mpm)
[root@localhost apache2]# bin/apachectl -l
Compiled in modules:
  core.c
  mod_so.c
  http_core.c
  prefork.c

拷贝文件

  1. 拷贝php库文件
[root@localhost apache2]# pwd
/usr/local/apache2
[root@localhost apache2]# ll modules/libphp5.so 
-rwxr-xr-x. 1 root root 4592768 730 09:55 modules/libphp5.so
  1. 拷贝php和nagios配置文件
[root@localhost conf]# pwd
/usr/local/apache2/conf
[root@localhost conf]# ll extra | grep -v httpd
总用量 76
-rw-r--r--. 1 root root  1679 730 09:23 nagios.conf
-rw-r--r--. 1 root root   691 730 09:23 php.conf
-rw-r--r--. 1 root root  3161 730 09:20 proxy-html.conf

修改配置

  1. 编辑httpd.conf文件
vim httpd.conf 
  • 增加libphp5.so模块
# Example:
# LoadModule foo_module modules/mod_foo.so
LoadModule php5_module modules/libphp5.so
  • 取消注释cgi模块的注释
#LoadModule cgi_module modules/mod_cgi.so
LoadModule cgi_module modules/mod_cgi.so
  • 增加以下*.conf文件路径
# Server-pool management (MPM specific)
#Include conf/extra/httpd-mpm.conf

Include /usr/local/apache2/conf/extra/nagios.conf
Include /usr/local/apache2/conf/extra/php.conf

# Multi-language error messages
#Include conf/extra/httpd-multilang-errordoc.conf

设置systemd

  1. 编译systemd配置文件
vim /usr/lib/systemd/system/httpd.service

vim /etc/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=notify
EnvironmentFile=/etc/sysconfig/httpd
#ExecStart=/usr/local/apache2/bin/httpd $OPTIONS -DFOREGROUND
ExecStart=/usr/local/apache2/bin/httpd $OPTIONS -f /usr/local/apache2/conf/httpd.conf -DFOREGROUND
ExecReload=/usr/local/apache2/bin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target
  1. 加载systemd配置文件
systemctl daemon-reload

验证

  1. 启动服务
systemctl start httpd
[root@localhost conf]# netstat -ntlp | grep httpd
tcp6       0      0 :::80                   :::*                    LISTEN      26467/httpd   
  1. 重启服务
systemctl restart httpd
[root@localhost conf]# netstat -ntlp | grep httpd
tcp6       0      0 :::80                   :::*                    LISTEN      1695/httpd     
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值