CentOS 6.5最小化安装编译部署Apache HTTPD 2.4.25
操作系统环境为CentOS 6.5迷你版(mini)。若使用VMware虚拟机,网络适配器需设置为“桥接”模式以确保连通性。
编译前需预先安装开发工具集、兼容库及中文支持包,执行以下命令完成基础环境准备:
#yum groupinstall "Development tools" "Compatibility libraries" "Chinese Support [zh]" -y
同时安装man手册、vim编辑器及wget下载工具,以便后续操作。
#yum install man vim wget -y
本次目标为编译安装httpd-2.4.25版本。由于该版本对底层库有更高要求,必须优先处理apr和apr-util的编译安装。
因此,第一步是获取并编译安装较高版本的apr和apr-util库文件。
wget http://mirrors.hust.edu.cn/apache/apr/apr-1.5.2.tar.bz2 wget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.5.4.tar.bz2
2.1编译安装apr
tar xf apr-1.5.2.tar.bz2
cd apr-1.5.2
./configure --prefix=/usr/local/apr
echo $? ###如果执行结果是0,则继续执行make && make install
2.2编译安装apr-util
tar xf apr-util-1.5.4.tar.bz2
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
echo $? ###如果执行结果是0,则继续执行make && make install
接下来进行核心组件httpd-2.4.25的编译准备工作。
wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.25.tar.bz2
根据多次编译经验,若缺少pcre相关文件或openssl版本过低,会导致配置失败。
需执行如下命令安装相关依赖包:
yum install pcre-devel openssl openssl-devel -y
tar xf httpd-2.4.25
cd httpd-2.4.25
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/

若出现上述提示则继续执行:make && make install
再次执行echo$?检查返回值,若结果为0,表明httpd2.4.25编译成功,随后可进行简单配置以投入使用。
4、配置httpd服务
首先关闭Linux系统的防火墙服务。
service httpd stop
接着关闭SELinux安全模块。
setenforce 0
复制Apache启动脚本至系统初始化目录。
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
将httpd的可执行路径添加到系统环境变量中。
echo 'export PATH=$PATH:/usr/local/apache/bin' > /etc/profile.d/httpd.sh chmod +x /etc/profile.d/httpd.sh source /etc/profile.d/httpd.sh
编辑httpd的主配置文件。
vim /etc/httpd/httpd.conf
在ServerRoot配置项的下一行,添加ServerName localhost以消除警告。
若希望Apache服务加入开机自启动,需修改服务启动脚本。
vim /etc/init.d/httpd
在第二行下方添加以下内容: # chkconfig:235 85 15 # description: This is apache server
保存并退出编辑器。
执行命令service httpd start启动服务(若提示lynx找不到,请执行yum install lynx -y安装)。随后执行netstat -ntlp命令查看httpd进程是否启动以及80端口是否监听。
最后,在浏览器中输入虚拟机的IP地址进行测试。
It works!
若页面显示此内容,则证明Apache安装成功。
关键路径汇总:1、编译安装--默认的index.html首页位于/usr/local/apache/htdocs;2、配置文件路径:/etc/httpd/httpd.conf;3、启动脚本位置:/etc/init.d/httpd;4、cgi-bin文件目录:/etc/local/apache/cgi-bin