阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 7下 Apache 2.4.18编译安装详解

116次阅读
没有评论

共计 4522 个字符,预计需要花费 12 分钟才能阅读完成。

安装环境:CentOS Linux release 7.0.1406 (Core)

0x01

到官网 http://httpd.apache.org/download.cgi#apache24 下载 apache http 最新版

tar zxf httpd-2.4.18.tar.gz

[root@localhost httpd-2.4.18]# rpm -qa | grep apr          查看当前主机上是否安装 apr/apr-util, 这个库为 apache 提供跨平台的支持

[root@localhost httpd-2.4.18]# yum install apr apr-util   这两个包在光盘镜像都有,配置和 yum 源即可

 使用 yum 安装的 apr 位置信息

[root@localhost httpd-2.4.18]# rpm -ql apr
/usr/lib64/libapr-1.so.0
/usr/lib64/libapr-1.so.0.4.8
/usr/share/doc/apr-1.4.8
/usr/share/doc/apr-1.4.8/CHANGES
/usr/share/doc/apr-1.4.8/LICENSE
/usr/share/doc/apr-1.4.8/NOTICE
[root@localhost httpd-2.4.18]# rpm -ql apr-util
/usr/lib64/apr-util-1
/usr/lib64/libaprutil-1.so.0
/usr/lib64/libaprutil-1.so.0.5.2
/usr/share/doc/apr-util-1.5.2
/usr/share/doc/apr-util-1.5.2/CHANGES
/usr/share/doc/apr-util-1.5.2/LICENSE
/usr/share/doc/apr-util-1.5.2/NOTICE

0x02 Apache 编译选项

–prefix=/usr/local/apache 
–sysconfdir=/etc/httpd 
–with-apr=/usr/local/apr
–with-apr-util=/usr/local/apr-util 

–enable-so             // 打开 so 模块,so 模块是用来提 DSO 支持的,提供动态共享模块与 php 协作
–enable-ssl             //https 使用
–enable-cgi            // 为非线程方式工作的 mpm 使用
–enable-rewrite     // 支持 URL 重写
–enable-zlib          // 通用压缩机制
–with-pcre            // 支持 pcre
–enable-module=most      // 启用大多数常用的模块
–enable-mpms-shared=most        // 启用 MPM 支持的模式, 启用哪种 mpm(prefork,worker,event),使用 worker 或 event 时要另外一种方式编译
php(编译时使用了–enable-maintainer-zts 选项)
–with-mpm=MPM          // 指定默认的 mpm

–enable-deflate       // 传输压缩机制,节约带宽
–enable-cgid         // 以线程工作(worker/event)的 mpm 使用

更多的选项可以通过./configure –help 了解

官方的编译选项文档 http://httpd.apache.org/docs/current/programs/configure.html

 

0x03 安装

[root@localhost httpd-2.4.18]# ./configure –prefix=/usr/local/apache2 –sysconfdir=/etc/httpd –enable-so –enable-ssl –enable-cgi –enable-rewrite –enable-zlib –enable-module=most –enable-mpms-shared=most –with-mpm=event

使用以上编译选项进行编译,编译的时候发现报错,难道使用 yum 安装的 apr 就不行了吗? 还是因为版本问题导致的。其实这里说明 apr-config 文件,但是 apr 的 rpm 包并未包含,所以应该安装 apr-devel 的 rpm 包。这里用源码安装解决

checking for APR… configure: error: the –with-apr parameter is incorrect. It must specify an install prefix, a build directory, or an apr-config file.

1、到官网下载 apr 和 apr-util 源码安装。

[root@localhost httpd-2.4.18]# tar zxf /mymnt/mnt/apr-1.5.2.tar.gz -C /usr/local/src/
[root@localhost httpd-2.4.18]# tar zxf /mymnt/mnt/apr-util-1.5.4.tar.gz -C /usr/local/src/

 

[root@localhost apr-1.5.2]# ./configure –prefix=/usr/local/apr
[root@localhost apr-util-1.5.4]# ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr

[root@localhost httpd-2.4.18]# ./configure –prefix=/usr/local/apache2 –sysconfdir=/etc/httpd –enable-so –enable-ssl –enable-cgi –enable-rewrite –enable-zlib –enable-module=most –enable-mpms-shared=most –with-mpm=event –with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util

2、安装完 apr 后还需要安装 pcre,打算到官网下载的,很简洁的网页,但是下载页面打不开。在 yum 源中找到了

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

[root@localhost httpd-2.4.18]# yum install pcre-devel 

3、继续执行 checking whether to enable mod_ssl… configure: error: mod_ssl has been requested but can not be built due to prerequisite failures,这是因为缺少 openssl

[root@localhost httpd-2.4.18]# yum install openssl-devel

4、 最后出现的一个报错是 configure: error: MPM most does not support dynamic loading.

从字面上可以了解,此时将 –enbale-mpm-shared 改为 all 即可 

make && make install

0x04  如何启动

没有做任何设置尝试启动时  [root@localhost apache2]# bin/apachectl start

AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using localhost.localdomain. Set the ‘ServerName’ directive globally to suppress this message

更改下主机名即可或者直接忽略

Apache 没有带服务脚本,所以需要自己编写一个用来实现开机启动。当然这里临时使用的就略过了

附:编译安装后一般设置

1、导出头文件;以目录链接的形式来实现

[root@localhost]# ln -sv /usr/local/apache2/include/ /usr/include/httpd

2、输出二进制程序

[root@localhost]# vim /etc/profile.d/httpd24.sh

export PATH=/usr/local/apache2/bin:$PATH

[root@localhost]#. /etc/profile.d/httpd24.sh

3、导出 man 文件

[root@localhost]# vim /etc/man.config

MANPATH /usr/local/apache2/man

[root@localhost]# man -M /usr/local/apache2/man httpd

4、导出库文件

 把 lib 目录路径输出到 /etc/ld.so.conf.d

[root@localhost]#echo“/usr/local/apache2/lib”> /etc/ld.so.conf.d/httpd

5、服务脚本

写个启动脚本放置在 /etc/init.d/ 目录即可用 service 启动。

CentOS6.8 编译安装 Apache2.4.25、MySQL5.7.16、PHP5.6.29  http://www.linuxidc.com/Linux/2016-12/138993.htm

CentOS 6.6 下安装 Apache 2.2.31 http://www.linuxidc.com/Linux/2017-02/140803.htm

Apache 配置多站点访问及二级域名配置  http://www.linuxidc.com/Linux/2017-03/141339.htm

Ubuntu 16.04 LTS 安装 Apache2+PHP7.0+MySQL+phpMyAdmin 图文详解  http://www.linuxidc.com/Linux/2017-02/140098.htm

Apache 配置 https  http://www.linuxidc.com/Linux/2017-02/140801.htm

Linux 下 Apache 安装及实例  http://www.linuxidc.com/Linux/2017-02/140800.htm

Apache2.4.6 服务器安装及配置  http://www.linuxidc.com/Linux/2017-01/140006.htm

Ubuntu 16.04 下搭建 Web 服务器 (MySQL+PHP+Apache) 教程  http://www.linuxidc.com/Linux/2017-01/139570.htm

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-03/142003.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计4522字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中