如果在安装apache的时候入到 error: mod_deflate has been requested but can not be built due to prerequisite failures的错误,那是没有安装zlib包。centos下可以采用yum install zlib-devel, ubuntu下可以采用apt-get install zlib1g-dev.
一、软件环境
1、系统:Ubuntu11.04
2、Apache:httpd-2.4.6.tar.bz2
3、依赖包:
apr-1.4.8.tar.bz2、apr-util-1.5.2.tar.bz2(下载地址:http://apr.apache.org/download.cgi)
pcre-8.12.tar.bz2(下载地址:http://www.pcre.org)
二、安装过程
1、安装apr
#cd/桌面/
#tar -jxvf apr-1.4.8.tar.bz2
#cdapr-1.4.8
./configure --prefix=/usr/local/apr
#make
#make install
2、安装apr-util
#cd/桌面/
#tar -jxvf apr-util-1.5.2.tar.bz2
#cdapr-util-1.5.2
#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
#make
#make install
3、安装pcre
#cd/桌面/
#tar -jxvf pcre-8.30.tar.bz2
#cdpcre-8.30
#./configure --prefix=/usr/local/pcre
#make
#makeinstall
4、安装apache
#cd/work/tools/
#tar -jxvf httpd-2.4.6.tar.bz2
#cdhttpd-2.4.6
#./configure --prefix=/usr/local/apache --enable-so --enable-mods-shared=all --enable-cgi --enable-rewrite --enable-deflate --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-mpm=worker
#make
#make install
可以用./configure–help | grep apr 查看帮助。
--with-included-apr Use bundled copies of APR/APR-Util
--with-apr=PATH prefix for installed APR or the full path toapr-config
--with-apr-util=PATH prefix forinstalled APU or the full path to
其中出错:
mod_deflate has been requested but can not be built due to prerequisite failures(ubuntu centent)
5.几条命令
chkconfig --list httpd //查看httpd服务是否已存在
chkconfighttpd off //关闭系统自带了httpd的服务,如果存在httpd服务
/work/apache/bin/apachectl-k start //linux启动apache命令
netstat-an | grep :80 //查看linux80端口是否开启
ps-aux | grep httpd //linux下查看apache进程
chkconfig--add apache //添加apache服务
chkconfig--list apache //列出apache服务
netstat-an | grep :80 //查看linux的80端口是否关闭
ps-aux | grephttpd //查看是否存在httpd服务,若果之前自带httpd服务启动的话会导致新添加的apache服务启动失败
三、运行
1、进入/usr/local/apache/conf,将httpd.conf中:
#ServerNamewww.example.com:80
改为: ServerNamelocalhost:80
2、进入/work/apache/bin,执行#./apachectlstart
3、在浏览器输入http://127.0.0.1 地址即可访问。
Apache 的基本认证
首先需要确定你想要设定用户认证的文件夹,假设为/var/www/test/。
在/etc/apache2/apache2.conf文件中配置AccessFIleName .htaccess前面的注释符号去掉,
然后在配置文件apache2.conf或者是httpd.conf中加入内容 如下
<Directory "/var/www/test/"> Options Indexes MultiViews AllowOverride AuthConfig Allow from all </Directory>
然后在/var/www/test/文件夹下建立.htaccess文件,文件内容为
AuthName "You need to have the privilege to view this page ,Please log in : AuthType Basic AuthUserFile /etc/apache2/authpwd Require user maturn test #maturn
建立口令文件 并且为用户设置口令,输入命令
htpasswd -c /etc/apache2/authpwd maturn认证工作基本完成,下面在浏览器中输入 localhost/test 来验证是否成功