Apache安装及出错处理

环境:Ubuntu

 注意:非root用户在输入命令时,要在命令前加sudo。

【简单安装】

一般第一次安装Apache都较为顺利。

1. 下载并解压
官网地址:http://httpd.apache.org/

root@ubuntu:/home/qy/share# tar zxvf httpd-2.2.22.tar.gz
root@ubuntu:/home/qy/share# cd httpd-2.2.22

 在http-2.2.22里有文件README和INSTALL,用more命令可以阅读。

2. 配置

root@ubuntu:/home/qy/share/httpd-2.2.22# ./configure --prefix=/usr/local/apache

--prefix参数指定了将要安装到的目录。此时/usr/local下还没有该目录,make install后才会出现。

注意:Apache在安装时不会检查参数是否正确,错误的参数会直接被丢弃,不会报告给用户。所以使用echo $?命令检查是否有错误,当输出结果为0时表示没有错误。

3. 编译

root@ubuntu:/home/qy/share/httpd-2.2.22# make
扫描二维码关注公众号,回复: 753792 查看本文章

4. 安装

root@ubuntu:/home/qy/share/httpd-2.2.22# make install

5. 启动服务器

root@ubuntu:/home/qy/share/httpd-2.2.22# cd /usr/local/apache/bin
root@ubuntu:/usr/local/apache/bin# ./apachectl start

 为了以后使用方便,可以把启动文件apachectl复制到/sbin下,以后直接apachectl start启动。

#vi /etc/rc.local

增加一行 /sbin/apachectl start

6. 验证Apache是否工作

此时,服务器端窗口应该显示:

#ps -e|grep httpd

在客户端浏览器输入服务器的IP地址(或者http://localhost),IE应该显示:It works!画面。

Ubuntu重启后,需要重启Apache:   apachectl start

停止服务器:  ./apachectl stop

重启服务器:  ./apachectl graceful  或   ./apachectl restarted

 

通常,第一次安装Apache没有什么问题,但以后安装,如果没有apr,apr-util,pcre,在执行./configure的配置过程中可能遇到的错误:

make[2]: *** [install] Error 1

make[2]: Leaving directory `/tmp/httpd-2.2.22/srclib/apr-util'

make[1]: *** [install-recursive] Error 1

make[1]: Leaving directory `/tmp/httpd-2.2.22/srclib'

make: *** [install-recursive] Error 1

Apache2.0.x与Apache2.2.x在apr上有本质的区别,前者为依赖公用apr,后者依赖于自身的apr。2.0.x的编译基本上没有 apr方面的问题,除非,在编译前,安装了非2.0.x所需的apr,如果是这样,则需要将已经安装的apr去除,然后再编译。HTTP Sever2.2.22修复了不少重要安全问题,包含APR(Apache Portable Runtime)1.4.5和APR-util(Apache Utility Library)1.4.2。因此不需要像网上其它教程那样从外部找源码安装apr和apr-util。将安装前已存在于系统中的apr去除后,再编译 apache2.2.x自身srclib里的apr和apr-util。其它操作系统这样解决就没问题了,但是Ubuntu不太一样。安装完apr和 apr-util后,./configure配置Apache时可能会出现下面错误:

configure: error: Cannot use an external APR with the bundled APR-util

configure: error: APR version 1.2.0 or later is required

 srclib目录中有apr,apr-util,pcre三个源码包,其中pcre是不可用的,编译不出来,有如下错误:

libtool: compile: unrecognized option `-DHAVE_CONFIG_H'

libtool: compile: Try `libtool --help' for more information.

make: *** [pcrecpp.lo] Error 1

ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 上下载的pcre-8.30也不可用。不妨用make check命令查看下错误出在什么地方。一般怀疑是g++版本低,更新即可。我没有这样做,而是直接用apt-get install libpcre3-dev安装了pcre后,再安装apache就没问题了。

【推荐完整步骤】

安装包解压:httpd-2.2.22.tar.gz和httpd-2.4.2.tar.gz,当我纠结在上述错误的时候,最新版2.4.2发布 了。因为后者scrlib不提供apr,apr-util,pcre,因此借用了较低版本的。注意:用2.2.22做下面的第4步会出错。

1. 安装apr

root@ubuntu:/home/qy/share# cd httpd-2.2.22
root@ubuntu:/home/qy/share/httpd-2.2.22# cd apr
root@ubuntu:/home/qy/share/httpd-2.2.22/apr# ./configure --prefix=/usr/local/apr
root@ubuntu:/home/qy/share/httpd-2.2.22/apr# make
root@ubuntu:/home/qy/share/httpd-2.2.22/apr# make install

 2. 安装apr-util

root@ubuntu:/home/qy/share/httpd-2.2.22/apr# cd ..
root@ubuntu:/home/qy/share/httpd-2.2.22# cd apr-util
root@ubuntu:/home/qy/share/httpd-2.2.22/apr-util# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
root@ubuntu:/home/qy/share/httpd-2.2.22/apr-util# make
root@ubuntu:/home/qy/share/httpd-2.2.22/apr-util# make install

 3. 安装pcre

root@ubuntu:/home/qy/share/httpd-2.2.22/apr-util# apt-get install libpcre3-dev
 

4. 安装apache

root@ubuntu:/home/qy/share/httpd-2.2.22/apr-util# cd /home/qy/share/httpd-2.4.2
root@ubuntu:/home/qy/share/httpd-2.4.2# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-dav --enable-mainer-mode --enable-rewrite
root@ubuntu:/home/qy/share/httpd-2.4.2# make
root@ubuntu:/home/qy/share/httpd-2.4.2# make install

Apache作为开源服务器,在编译前需要了解系统的库安装情况,某些模块需要依赖于特定的库,如果这些库不存在,配置脚本将自动忽略这些库的编 译。经过检测时候会生成合适的MakeFile文件。这里特别提醒一句,如果直接执行配置脚本,是不会编译额外的模块的,我们希望使用额外模块时,需要在 运行配置脚本命令后加入参数,让其尽最大可能编译可用的库。

5. 启动apache

root@ubuntu:/home/qy/share/httpd-2.4.2# /usr/local/apache/bin/apachectl start

附:

–prefix=/usr/local/apache //体系无关文件的顶级安装目录PREFIX ,也就Apache的安装目录。
–enable-module=so //打开 so 模块,so 模块是用来提 DSO 支持的 apache 核心模块
–enable-mods-shared=all //编译全部的模板,对于不需要我们可以在httpd.conf去掉。
–enable-cache //支持缓存
–enable-file-cache //支持文件缓存
–enable-mem-cache //支持记忆缓存
–enable-disk-cache //支持磁盘缓存
–enable-static-support //支持静态连接(默认为动态连接)
–enable-static-htpasswd //使用静态连接编译 htpasswd – 管理用于基本认证的用户文件
–enable-static-htdigest //使用静态连接编译 htdigest – 管理用于摘要认证的用户文件
–enable-static-rotatelogs //使用静态连接编译 rotatelogs – 滚动 Apache 日志的管道日志程序
–enable-static-logresolve //使用静态连接编译 logresolve – 解析 Apache 日志中的IP地址为主机名
–enable-static-htdbm //使用静态连接编译 htdbm – 操作 DBM 密码数据库
–enable-static-ab //使用静态连接编译 ab – Apache HTTP 服务器性能测试工具
–enable-static-checkgid //使用静态连接编译 checkgid
–disable-cgid //禁止用一个外部 CGI 守护进程执行CGI脚本
–disable-cgi //禁止编译 CGI 版本的 PHP我们不再使用worker模式编译apache,worker模式和php貌似有一些不协调不稳定之处。所以使用了默认的perfork模式。

【参考文献】

http://code.sh/tag/apache/

http://hi.baidu.com/rel_conquer/blog/item/477d7e1fb2610166f624e4cd.html

出错处理:

(13)Permission denied: make_sock: could not bind to address 0.0.0.0:80

解决办法:

semanage port -l|grep http
semanage port -a -t http_port_t -p tcp 81

这个两个命令一是查看,一个是添加,添加完再查看一遍,如果有81,则成功。

猜你喜欢

转载自xiamidatou-gmail-com.iteye.com/blog/1725630
今日推荐