本文安装的httpd版本为httpd 2.4.4
安装之前确保 Development Libraries与Development tools安装上。安装方法参考:http://www.linuxidc.com/Linux/2016-04/130080.htm 与 http://www.linuxidc.com/Linux/2016-04/130081.htm
一、编译安装
1、解决依赖关系
安装httpd 2.4.4时首先需要解决依赖关系,httpd 2.4.4需要较新版本的apr和apr-util。升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包。本文选择第一种方法来进行升级。在这里我们下载 apr-1.4.6.tar.bz2与apr-util-1.5.2.tar.bz2版本。为了以后不必要的麻烦,在这里一定要保证系统时间正确,不正确的(data自行修改)。
apr和apr-util的下载路径为:http://archive.apache.org/dist/apr/
(1)首先根据惯例剪切apr与apr-util到/usr/local/src下,然后进行解压操作
mv apr-1.4.6.tar.bz2 /usr/local/src
mv apr-util-1.5.2.tar.bz2 /usr/local/src
tar -xjvf apr-1.4.6.tar.bz2
tar -xjvf apr-util-1.5.2.tar.bz2
(2)编译安装apr
cd apr-1.4.6
./configure --prefix=/usr/local/apr #安装在/usr/local/下 命名为apr
make
make install
(3)编译安装apr-util
cd apr-util-1.5.2
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install
(如果是yum安装则
1:如果包是通过yum或者rpm方式安装)
[root@localhost yum.repos.d]# rpm -qa //找出系统所有的包,找到对应的文件名
[root@localhost yum.repos.d]# rpm -ql php-mysql-5.4.16-23.el7_0.3.x86_64
二、后续操作
1、启动httpd
两种方法:第一种、/usr/local/apache/bin/apachectl start
第二种方法:先修改http.pid文件位置打开配置文件增加一行
vim /etc/httpd/httpd.conf 增加PidFile “/var/run/httpd.pid”
为了启动httpd更加方便,
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=$?
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f ${pidfile} ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL
将以上代码加入到vim /etc/init.d/httpd中
而后为此脚本赋予执行权限:
chmod +x /etc/rc.d/init.d/httpd
加入服务列表:
chkconfig --add httpd
给3,5启动
chkconfig --level 3,5 httpd on
最后加路径
将 export PATH=$PATH:/usr/local/apache/bin
vim /etc/profile.d/httpd.sh完成后重新登录就可以了。推荐使用第二种方法
三、验证
安装成功!