环境准备
- 本机环境:
uname -rcat /etc/redhat-release
1.1 软件包版本:apr 1.6.3apr-util 1.6.1httpd 2.4.33
- 准备工作:
yum -y updateyum -y install gcc openssl openssl-devel openssl-clients pcre pcre-devel perl perl-devel pcre expat-devel
2.1. 在官网下载源码包:cd /usr/
2.2 下载并解压后,进行文件操作wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gzwget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.6.3.tar.gzwget http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.33.tar.gz
lsmv apr-1.6.3 aprmv apr-util-1.6.1 apr-utillsmv apr apr-util httpd-2.4.33/srclib/ls /usr/httpd-2.4.33/srclib/cd /usr/httpd-2.4.33/
安装过程
- 执行编译命令
./configure \--prefix=/usr/local/apache2 \--with-included-apr \--enable-so \--enable-deflate=shared \--enable-expires=shared \--enable-rewrite=shared \--with-pcre \--with-ssl
注:
- P.S.如果可以编译/安装成功,不需要对apr和apr-util 安装。否则还是要装
--prefix=/usr/local/apache2指定安装路径--with-included-aprApache portable Run-time libraries,Apache可移植运行库--enable-s激活apache的dso模块的支持,以后可以用DSO方式编译安装共享模块。--enable-deflate=shared提供对内容的压缩传输编码,shared表示动态加载,需要时再加载模块。--enable-expires=shared允许通过配置文件控制http的"Expires"和 "Cache-Control"头内容,对图片,css,js等内容配置客户端浏览器缓存。--enable-rewrite=shared提供基于url 规则的重写功能--with-pcreperl兼容正则表达式库--with-ssl支持ssl
- 编译和安装
启动apache
- 编译和安装
启动前,应当设置:
vi /usr/local/apache2/conf/httpd.conf查找到/ServerName,添加一行:ServerName xxx(服务器的hostname):80
/usr/local/apache2/bin/apachectl,目录请根据实际情况判断编译安装的httpd添加到开机自启
cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/cd /etc/rc.d/init.d/mv apachectl httpdvi httpd 在开头添加三行:#!/bin/bash#chkconfig:345 61 61#description:Apache httpdchkconfig --add httpdchkconfig --list|grep httpd 确认没问题,添加进去了chkconfig --level |2345 httpd on 或chkconfig httpd onchkconfig --list |grep httpd
问题总结:
运行
service httpd status的时候,提示信息如图:
查询解决方法,可能是没有status这个参数。。。就很无语,如图:
- 其他命令,如
service httpd start;service httpd restart;service httpd stop,可以运行,无报错。
- 其他命令,如
