PDA

View Full Version : CentOS6.5下Apache2.4.7的安装笔记


Matfield Green
2016-05-21, 08:39 AM
一、准备安装环境
安装make以及安装C++编译环境:
yum -y install gcc gcc-c++ automake autoconf libtool make wget


1.选定源码目录
可以是任何目录,本文选定的是/usr/local/src

cd /usr/local/src

2.安装PCRE库
http://sourceforge.net/projects/pcre/files/pcre 下载最新的 PCRE 源码包,使用下面命令下载编译和安装 PCRE 包:

cd /usr/local/src
wget http://sourceforge.net/projects/pcre/files/pcre/8.34/pcre-8.34.tar.gz
tar -zxvf pcre-8.34.tar.gz
cd pcre-8.34
./configure
make
make install

3.安装 APR
cd /usr/local/src
wget http://mirror.bjtu.edu.cn/apache/apr/apr-1.5.0.tar.gz
tar -zxvf apr-1.5.0.tar.gz
cd apr-1.5.0

./configure --prefix=/usr/local/apr-1.5.0 //配置

make //编译

make test //测试

make install //安装

4.安装APR-UTIL
cd /usr/local/src
wget http://mirror.bjtu.edu.cn/apache/apr/apr-util-1.5.3.tar.gz
tar -zxvf apr-util-1.5.3.tar.gz
cd apr-util-1.5.3

./configure --prefix=/usr/local/apr-util-1.5.3

./configure --prefix=/usr/local/apr-util-1.5.3 --with-apr=/usr/local/apr-1.5.0/

make

make test

make install


5.安装apache
cd /usr/local/src
wget http://mirror.bjtu.edu.cn/apache/httpd/httpd-2.4.7.tar.gz
tar -zxvf httpd-2.4.7.tar.gz

cd httpd-2.4.7

./configure --prefix=/usr/local/apache --enable-mods-shared=all --with-apr=/usr/local/apr-1.5.0/ --with-apr-util=/usr/local/apr-util-1.5.3/ //--prefix指定安装路径,--enable-mods-shared启用所有支持的动态加载模块,--with-apr指定APR路径,--with-apr-util指定APR-util路径

make

make install

/usr/local/apache/bin/apachectl start //启动apache



二、注册apache为系统服务

cp /usr/local/apache/bin/apachectl /etc/init.d/httpd //把apache启动脚本复制到系统脚本目录下

vi /etc/init.d/httpd在第一行下插入
# chkconfig: 2345 85 35 //修改脚本用于在运行界别2345下自启动,并指定启动脚本序号为85,关闭脚本序号为35

chkconfig --add httpd //注册为自启动服务

三、修改防火墙设置

vi /etc/sysconfig/iptables //编辑iptables配置文件

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT //在适当位置插入

service iptables restart //重启防火墙服务
四、将apache安装为系统服务

# cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd


然后 vi /etc/rc.d/init.d/httpd 添加(# !/bin/sh下面)

# chkconfig: 2345 50 90
# description: Activates/Deactivates Apache Web Server
保存退出

最后,运行chkconfig把Apache添加到系统的启动服务组里面:
# chkconfig --add httpd
# chkconfig httpd on