您的位置:首页 > 运维架构 > Apache

centos7编译安装apache

2016-04-07 15:49 585 查看
在vm上编译安装了一下apache,vm环境是centos7。编译安装的apache版本是httpd-2.4.18。

编译与安装

编译安装采用“configure/make/make install”的方式进行。

./configure --prefix=/usr/local/apache2 --enable-so --enable-deflate --enable-expires --enable-rewrite --enable-cache --enable-file-cache --enable-mem-cache --disable-cgi --enable-static-support --with-mpm=worker  --enable-ssl --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --enable-headers


配置参数

比较懒,以下配置参数有部份引自此博客

–prefix:指定安装的目录;

–enable-rewrite:启用URL重写支持;

–enable-so:启用DSO(Dynamic Shared Objects动态共享目标),这个通常是默认启用;

–enable-cache:启用缓存支持;

–enable-headers:提供对HTTP请求头的控制;

–enable-expires:激活通过配置文件控制HTTP的“Expires:”和“Cache-Control:”头内容,即对网站图片、js、css等内容,提供客户端浏览器缓存的设置。这个是apache调优的一个重要选项之一;

–with-mpm=worker:选择apache mpm的模式为worker模式。为worker模式原理是更多的使用线程来处理请求,所以可以处理更多的并发请求。而系统

资源的开销小于基于进程的MPM

prefork。如果不指定此参数,默认的模式是prefork进程模式(–with-mpm=MPM)。这个是apache调优的一个重要选项之一;

–enable-deflate:提供对内容的压缩传输编码支持,一般是html、js、css等内容的站点。使用此参数会打打提高传输速度,提升访问者访问的体验。在生产环境中,这是apache调优的一个重要选项之一。

–enable-file-cache //支持文件缓存

–enable-mem-cache //支持记忆缓存

–enable-disk-cache //支持磁盘缓存

–enable-static-support //支持静态连接(默认为动态连接)

–enable-static-htpasswd //使用静态连接编译 htpasswd - 管理用于基本认证的用户文件

–enable-static-htdigest //使用静态连接编译 htdigest - 管理用于摘要认证的用户文件

–enable-static-rotatelogs //使用静态连接编译 rotatelogs - 滚动 apache 日志的管道日志程序

–enable-static-logresolve //使用静态连接编译 logresolve - 解析 apache 日志中的ip地址为主机名

–enable-static-htdbm //使用静态连接编译 htdbm - 操作 dbm 密码数据库

–enable-static-ab //使用静态连接编译 ab - apache http 服务器性能测试工具

–enable-static-checkgid //使用静态连接编译 checkgid

–disable-cgid //禁止用一个外部 cgi 守护进程执行cgi脚本

–disable-cgi //禁止编译 cgi 版本的 php

–disable-userdir //禁止用户从自己的主目录中提供页面

–enable-authn-dbm=shared // 对动态数据库进行操作。rewrite时需要。

还有许多的配置选项,可以通过“./configure –help”来获取配置选项信息。

安装过程中的问题与解决方法

1、如果你的环境中连gcc都没有安装的话,那就先安装gcc。

#yum -y install gcc


2、configure: error: APR not found. Please read the documentation.

系统中未安装APR,可以到apr.apache.org上下载安装。需要安装的有两个,一个是apr,另一个是apr-util。先安装apr,然后安装apr-util,在安装apr-util时需要指定参数
--with-apr=PATH
,apr默认是安装在
/usr/local/apr
目录,所以参数可写为
--with-apr=/usr/local/apr/


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

需要安装pcre,到www.pcre.org/上下载安装。当然yum也可以直接安装:

yum install -y pcre pcre-devel


安装pcre时可能遇到另一个问题:configure: error: You need a C++ compiler for C++ support.表示没有安装c++支持,安装后继续

#yum -y install gcc-c++


4、checking whether to enable mod_deflate… configure: error: mod_deflate has been requested but can not be built due to prerequisite failures

系统中缺少zlib,安装后继续

#yum -y install zlib-devel


5、checking whether to enable mod_ssl… configure: error: mod_ssl has been requested but can not be built due to prerequisite failures;

系统中缺少openssl,继续安装

yum -y install openssl openssl-devel


6、安装完成后,启动apache时,可能会出现如下提示:

AH00557: httpd: apr_sockaddr_info_get() failed for bogon

AH00558: httpd: Could not reliably determine the server’s fully

qualified domain name, using 127.0.0.1. Set the ‘ServerName’ directive

globally to suppress this message

出现此问题后apache仍然会启动,需要先关掉apache:
/usr/local/apache2/bin/apachectl stop
,然后修改httpd.conf配置文件,设置ServerName选项,本地测试可设置为
ServerName localhost:80
,然后重新启动apache即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息