运行./configure 命令进行编译源代码,
--prefix=/usr/local/apach2 是设置编译安装到的系统目录,
--enable-s 参数是使httpd服务能够动态加载模块功能,
--enable-rewrite 是使httpd服务具有网页地址重写功能。
3、启动apache:
/usr/local/apache2/bin/apachectl start
如果出现以下问题
httpd: apr_sockaddr_info_get() failed for hw2-devel
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
原因:这个问题应该是没有在/etc/apache2/conf/httpd.conf中设置ServerName,所以apache会用主机上的名称来取代,首先会去找/etc/hosts中有没有主机的定义
解决办法:(1)可以设定httpd.conf文件中得ServerName,如下:ServerName localhost:80
(2)在/etc/hosts中填入自己的主机名称,如下127.0.0.1 hw2-devel(用户名称)
4、将apache加入到系统服务,用service命令控制Apache的启动和停止
首先以apachectl脚本为模板生产Apache服务控制脚本
#grep -v "#" /usr/local/apache2/bin/apachectl > /etc/init.d/httpd
用vi编辑Apache服务控制脚本
#vi /etc/init.d/httpd
在文件最前面插入下面的行,使其支持chkconfig命令
#!/bin/sh
#chkconfig:2345 85 15
#description:Aapche is a World Wide Web server.
总:
#!/bin/sh
#
# Startup script for the Apache Web Server
#
# chkconfig: 345 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# pidfile: /usr/local/apache2/logs/httpd.pid
# config: /usr/local/apache2/conf/httpd.conf
# Source function library.
. /etc/rc.d/init.d/functions
# See how we were called.
case "$1" in
start)
echo -n "Starting httpd: "
daemon /usr/local/apache2/bin/httpd -DSSL
echo
touch /var/lock/subsys/httpd
;;
stop)
echo -n "Shutting down http: "
killproc httpd
echo
rm -f /var/lock/subsys/httpd
rm -f /usr/local/apache2/logs/httpd.pid
;;
status)
status httpd
;;
restart)
$0 stop
$0 start
;;
reload)
echo -n "Reloading httpd: "
killproc httpd -HUP
echo
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
保存后退出vi编辑器,再执行下面的命令增加Apache服务控制脚本执行权限
#chmod +x /etc/init.d/httpd
执行下面的命令将Apache服务加入到系统服务:
#chkconfig —add http
执行下面的命令检查Apache服务是否已经生效:
#chkconfig —list httpd
命令输出类似下面的结果,3,4,5都为on表明apache服务已经生效,
#httpd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
2、3、4、5运行级别随系统启动而自动启动,以后可以使用service命令控制Apache的启动和停止。
启动Apache服务: service httpd start
关闭Apache服务: service http stop
如果345为off,可以先删除掉,然后再添加
#chkconfig —del httpd
#chkconfig —add http
#chkconfig —list httpd