→环境配置
1. 安装C、C++编译器:
[[email protected] local]# yum install -y gcc gcc-c++
2. 安装APR 1.5.2(解决apr not found问题):
[[email protected] local]# wget http://apache.fayea.com//apr/apr-1.5.2.tar.gz
[[email protected] local]# tar -zxf apr-1.5.2.tar.gz
[[email protected] apr-1.5.2]# cd apr-1.5.2
[[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr
[[email protected] apr-1.5.2]# make
[[email protected] apr-1.5.2]# make install
如编译configure过程中,遇到 rm: cannot remove `libtoolT‘ 错误,编辑 configure文件,查找 $RM "$cfgfile" 这个地方,用#注释掉,然后就可以了。
3.安装APR-UTIL 1.5.4(解决APR-util not found问题):
[[email protected] local]# wget http://apache.fayea.com//apr/apr-util-1.5.4.tar.gz
[[email protected] local]# tar -zxf apr-util-1.5.4.tar.gz
[[email protected] local]# cd apr-util-1.5.4
[[email protected] apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config
[[email protected] apr-util-1.5.4]# make
[[email protected] apr-util-1.5.4]# make install
4. 安装PCRE 8.39 (解决pcre-config for libpcre not found问题):
[[email protected] local]# wget https://sourceforge.net/projects/pcre/files/pcre/8.39/pcre-8.39.tar.gz
[[email protected] local]# tar -zxf pcre-8.39.tar.gz
[[email protected] local]# cd pcre-8.39
[[email protected] pcre-8.39]# ./configure --prefix=/usr/local/pcre
[[email protected] pcre-8.39]# make
[[email protected] pcre-8.39]# make install
5. 安装zlib-devel (解决mod_deflate has been requested but can not be built due to prerequisite failures):
[[email protected] httpd-2.4.23]# yum install -y zlib-devel
→安装apache(httpd-2.4.23)
[[email protected] local]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.23.tar.gz
[[email protected] httpd-2.4.23]# tar -zxf httpd-2.4.23.tar.gz
[[email protected] local]# cd httpd-2.4.23
[[email protected] httpd-2.4.23]#
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite
[[email protected] httpd-2.4.23]# make
[[email protected] httpd-2.4.23]# make install
./configure 后面参数说明:
--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre #路径为源码目录
--prefix=/usr/local/apache2 #apache的默认安装路径。
--enable-deflate #提供对内容的压缩传输编码支持,提高传输速度。调优参数
--enable-expires #对网站图片,js,css等内容,提供在客户端浏览器缓存设置。调优参数
--enable-headers #允许对HTTP请求头控制。
--enable-so #激活apache的DSO支持,以后可以以DSO的方式编译安装共享模块。
--enable-rewrite #提供基于URL规则的重写功能。
--with-mpm=worker #使用线程方式来处理请求,系统资源开销小于 MPM perfork。调优参数
安装完成后检查编译安装情况:
1. 静态加载的模块(-l 参数)
[[email protected] bin]# /usr/local/apache2/bin/apachectl -l
Compiled in modules:
core.c
mod_so.c
http_core.c
worker.c
2. 基于当前配置加载的所有模块(-M 参数)
[[email protected] bin]# /usr/local/apache2/bin/apachectl -M
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_worker_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)
3. 检查编译参数:
[[email protected] bin]# /usr/local/apache2/bin/apachectl -V
Server version: Apache/2.4.23 (Unix)
Server built: Jul 7 2016 10:28:32
Server‘s Module Magic Number: 20120211:61
Server loaded: APR 1.5.2, APR-UTIL 1.5.4
Compiled using: APR 1.5.2, APR-UTIL 1.5.4
Architecture: 32-bit
Server MPM: worker
threaded: yes (fixed thread count)
forked: yes (variable process count)
Server compiled with....
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT="/usr/local/apache2"
-D SUEXEC_BIN="/usr/local/apache2/bin/suexec"
-D DEFAULT_PIDLOG="logs/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="conf/mime.types"
-D SERVER_CONFIG_FILE="conf/httpd.conf"
→启动apapche服务
[[email protected] bin]# /usr/local/apache2/bin/apachectl start
bin目录主要文件作用:
/usr/local/apache2/bin/
├── ab # Apache服务器性能测试工具
├── apachectl #Apache启动脚本
├── apxs #Apache服务器编译和安装扩展模块的工具
├── htpasswd #建立和更新基本认证文件
├── httpd #Apache控制命令程序
└── rotatelogs #Apache自带日志轮询工具
conf目录主要文件作用:
/usr/local/apache2/conf/
├── extra #Apache辅助配置文件目录
│ ├── httpd-autoindex.conf
│ ├── httpd-dav.conf
│ ├── httpd-default.conf
│ ├── httpd-info.conf
│ ├── httpd-languages.conf
│ ├── httpd-manual.conf
│ ├── httpd-mpm.conf
│ ├── httpd-multilang-errordoc.conf
│ ├── httpd-ssl.conf
│ ├── httpd-userdir.conf
│ ├── httpd-vhosts.conf
│ └── proxy-html.conf
├── httpd.conf #Apache主配置文件
htdocs目录
/usr/local/apache2/htdocs/
└── index.html #默认首页文件
apache日志目录
/usr/local/apache2/logs/
├── access_log
└── error_log
apache模块目录
/usr/local/apache2/modules/