1. 程式人生 > >apache安裝

apache安裝

esc 必須 functions res 方式 com ech owin with

一、編譯安裝
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
(4) httpd-2.4.4編譯過程也要依賴於pcre-devel軟件包,需要事先安裝。此軟件包系統光盤自帶,因此,找到並安裝即可。
yum -y install pcre-devel
到此為止基本上解決了依賴關系。
2、編譯安裝httpd-2.4.4
下載httpd-2.4.4.tar.bz2下載地址為https://archive.apache.org/dist/httpd/
(1)首先根據慣例剪切httpd-2.4.4.tar.bz2到/usr/local/src下,然後進行解壓操作
mv httpd-2.4.4.tar.bz2 /usr/local/src
tar -xjvf httpd-2.4.4.tar.bz2
(2)編譯安裝httpd (以上沒有問題,但這裏會出現一下小問題,應該是參數有些沒有的等等,逐個百度解決就行了,最後修改httpd.cnf端口那裏就能訪問了)
cd httpd-2.4.4
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewirte --enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
解釋:
--enable-so:支持動態共享模塊,如果支持php將不能與apache一起工作。必須要有
--enable-ssl:啟用ssl功能,如果不啟用將無法使用https
--enable-mpms-shared=all:prefork、worker、event
--with-mpm=event:event為默認
--enable-rewrite:支持URL重寫
--enable-cgi :支持cgi
--enable-cgid:httpd使用event或者worker得啟用被線程方式訪問
--enable-modules=most :啟用大多數模塊
--enable-mods-shared=most:啟用大多數共享模塊
(3)setenforce 0 關掉selinux。(臨時關閉)
永久關閉 vim /etc/selinux/config

二、後續操作
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 [email protected]
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完成後重新登錄就可以了。推薦使用第二種方法

apache安裝