源码安装apache
所需软件包:
httpd_-2.4.6.tar.bz2
apr-1.4.6.tar.gz(apache的一个可移植的运行库)
apr-util-1.5.1.tar.gz
实验环境:readhat 5.4
步骤:
把所需要的软件包通过终端软件传入虚拟机
[root@localhost ~]# mkdir /mnt/cdrom-------------建立光盘挂载点
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom/---------------挂载光盘
[root@localhost ~]# cd /mnt/cdrom/Server ----------------------进入光盘主目录
利用yum安装所需要的软件包
[root@localhost ~]#yum apr-devel-1.2.7-11.e15_3.1.i386.rpm-----安装apr 开发包
安装apr-1.4.6运行库
[root@localhost ~]#tar -zxvf apr-1.4.6.tar.gz -C/usr/local/src/------拆包到/usr/local/src/目录下
[root@localhost ~]#cd /usr/local/src/apr-1.4.6/---------------进入apr的主目录
配置apr-1.4.6
[root@localhost apr-1.4.6]#./configure --------------------默认安装到/usr/local目录下自动生成的apr目录下
[root@localhost apr-1.4.6]#make--------------------------编译
[root@localhost apr-1.4.6]#make install------------------编译
[root@localhost apr-1.4.6]#cd
安装apr-util-1.5.1
[root@localhost ~]#tar -zxvf apr-util-1.5.1.tar.gz -C /usr/local/src/--------拆包到/usr/local/src/目录下
[root@localhost ~]#cd /usr/local/src/apr-util-1.5.1/------------进入主目录
[[email protected]]#./config--with-apr=/usr/local/apr/bin/apr-1-config
----------配置
[root@localhost apr-util-1.5.1]#make-------------------------编译
[root@localhost apr-util-1.5.1]#make install----------------编译
[root@localhost apr-util-1.5.1]#cd
安装pcre 及其开发包(别问为什么要装这个,不装会出问题的。。。)
[root@localhost ~]#ll /mnt/cdrom/Server/pcre*
[root@localhost ~]#rpm -ivh /mnt/cdrom/Server/pcre-6.6-2.el5_1.7.i386.rpm
[root@localhost~]#rpm-ivh /mnt/cdrom/Server/pcre-devel-6.6-2.e15_1.7.i386.rpm
[root@localhost ~]#vim /etc/ld.so.conf.d/apr.conf
写入路径/usr/local/apr/lib(让系统调用运行库)
[root@localhost ~]#ldconfig加载
安装http2.4.4
[root@localhost ~]#tar -jxvf httpd-2.4.6.tar.bz2 -C /usr/local/src/
[root@localhost ~]#cd /usr/local/src/httpd-2.4.4/
[[email protected]]#./config--prefix=/usr/local/apache--sysconfdir=/etc/httpd(配置文件目录)--with-apr=/usr/local/apr/bin/apr-1-config(要指定apr-config的完整路径)
[root@localhost httpd-2.4.6]# make
[root@localhost httpd-2.4.6]# make install
[root@localhost httpd-2.4.6]# cd /usr/local/bin/
[root@localhost bin]# ./apachectl start
[root@localhost bin]# netstat -tupln |grep 80(查看80端口是否启动)
此时调用的是apachectl,那么我们想调用自己的脚本来启动apache呢?
那就写脚本吧。。
[root@localhost bin]# cd /etc/init.d
[root@localhost init.d]#vim httpd
#!/bin/bash
#descriptionion: httpd server
#chkconfig: -88 90
HTTPD=’/usr/local/apache/bin/httpd’
CONFFILE=’etc/httpd/httpd.conf’
. /etc/init.d/FUNCTIONS
start() {
[-f /var/lock/subsys/http ] && echo “httpd is starting....”
echo -n “httpd is starting......”
sleep 1
$HTTPD -f $CONFFILE && RETVAL=0||RETVAL=1
[$RETVAL -eq 0] &&touch /var/lock/subsys/http && echo -e “33[31m [ok] 33[0m”||echo -e “33[31m [fail] 33[0m”
}
stop (){
Echo -n “httpd is stoping.....”
sleep 1
killproc httpd && RETVAL=0||RETVAL=1
[$RETVAL -eq 0] && rm -rf /var/lock/subsys/http ||echo -e “33[31m [fail] 33[0m”
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo “Usage:start|stop|restart”
;;
esac
[root@localhost init.d]#chmod a+x httpd
[root@localhost init.d]#chkconfig httpd on(把httpd服务设置开机自启动)
结束
有可能出现的错误
解决办法
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
把以下两行禁用掉
出现的问题
解决办法