httpd源碼安裝

#HTTPD編譯安裝步驟詳解
httpd屬於Apache軟件基金會組織,官網地址:https://www.apache.org
.
安裝HTTPD需要先解決其依賴關係,安裝gcc、pcre、expat、apr、apr-util。
gcc、pcre、expat使用yum安裝即可:
yum install -y gcc* pcre-devel expat-devel
.
arp和arp-util是一個共享的函數庫,他的功能使httpd不用考慮底層操作系統的不同,可以方便移植。
.
arp使用編譯安裝
鏈接:http://apr.apache.org/download.cgi/arp-1.7.0.tar.gz
我們將arp和arp-util下載到/usr/local/src/目錄下,使用源碼包安裝過程安裝。
tar xf arp-1.7.0.tar.gz
cd apr-1.7.0
./configure --prefix=/usr/local/apr #注:可以使用./configuer -help 查看其他參數,這裏不做解釋;
make && make install
.
apr-util也是用源碼方式安裝
鏈接:http://apr.apache.org/download.cgi/arp-util-1.6.1.tar.gz
tar xf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr #--with-apr是聲明apr的位置,因爲apr-util是依賴apr的工具包。
make && make install
這樣我們就解決了依賴關係了,開始準備httpd;
.
官網下載地址:http://httpd.apache.org/download.cgi#apache24
將源碼包同樣放在/usr/local/src/目錄下
tar xf httpd-2.4.39.tar.gz
cd httpd-2.4.39
./configure --prefix=/usr/local/httpd --sysconfdir=/etc/httpd --enable-so --enable-mod_ssl --enable-cgi --enable-cgid --enable-rewirte --enbale-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util #注:./configure可以查看其他參數,根據自己需要添加。
make && make install
.
以下是httpd源碼編譯參數介紹:
--prefix=/usr/local/httpd #配置httpd安裝路徑
--sysconfdir=/etc/httpd #httpd主配置文件路徑
--enable-so #支持動態共享模塊
--enbale-mod_ssl #啓用ssl功能,不啓用則無法使用https功能
--enable-cgi #支持cgi協議
--enable-cgid #如果使用vorker和event模式則需要加此項
--enable-rewirte #支持URL重寫的功能
--enable-modules=most #啓用模塊功能,most(大多數的),all(全部的),few(少數的)
--enable-mods-shared=most #啓用共享模塊
--enable-mpms-shared=all #mpm(多道處理模塊),all表示三種模式都會做成模塊添加(prefork、vorker、event)
--with-apr=/usr/local/apr #聲明apr安裝位置
--with-apr-util=/usr/local/apr-util #聲明apr-util安裝位置
.
安裝完成後在/usr/local/httpd/目錄下會生成一下目錄
bin:二進制程序文件
cgi-bin:執行cgi程序時的位置
error :存放一些錯誤信息
htdocs :網頁文檔的位置
icons :提供一些圖標
include :頭文件
logs :日誌文件
man:幫助文件
manual :安裝手冊
modules:模塊目錄
.
httpd默認當selinux啓動時,httpd啓動不了,所以我們將其關掉
查看:getenforse
臨時修改:setenforse 0
永久修改編輯/etc/selinux/config文件將
SELINUX=disabled
改爲disabled即可
.
我們可以使用/bin/apachectl start 啓動httpd服務
netstat -nlpt 查看端口是否已經監聽
添加到PATH變量中,編輯文件/etc/profile.d/httpd.sh
export PATH=$PATH:/usr/local/httpd/bin
默認httpd不支持service服務,需要自己寫腳本,編輯/etc/init.d/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
然後chmod +x /etc/init.d/script_name即可
.
這樣就可以輕鬆啓動或關閉httpd服務了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章