1. 程式人生 > >centos7原始碼編譯安裝httpd、加入systemctl並設定開機自啟動

centos7原始碼編譯安裝httpd、加入systemctl並設定開機自啟動

1、所需軟體:

apr-1.6.3.tar.gz

(下載地址:http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.6.3.tar.gz)

apr-util-1.6.1.tar.gz

(下載地址:http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz)

httpd-2.4.29.tar.gz

(下載地址:http://mirrors.shu.edu.cn/apache//httpd/httpd-2.4.29.tar.gz)

以上所需包均可使用wget獲取

2、yum  -y  install  gcc  pcre  pcre-devel  libtool  libxml2-devel

3、安裝apr:

#解壓
tar  -xzf  apr-1.6.3.tar.gz
cd  apr-1.6.3/ --進入目錄
./configure  &&  make  &&  make  install --配置 ,編譯 ,安裝

4、安裝apr-util:

tar  -xzf  apr-util-1.6.1.tar.gz --解壓
cd  apr
-util-1.6.1/ --進入目錄 ./configure --with-apr=/usr/local/apr/ --指定安裝目錄 make && make install --編譯 安裝

5、安裝httpd:

tar  -xzf  httpd-2.4.29.tar.gz       --解壓
cd httpd-2.4.29/    --進入目錄
./configure  &&  make  &&  make  install --配置  編譯 安裝

6、編寫啟動指令碼:vim httpd

#!/bin/bash
# chkconfig: 12345 80 90
function start_http()
{
/usr/local/apache2/bin/apachectl  start
}
function stop_http()
{
 /usr/local/apache2/bin/apachectl  stop
}
case "$1" in
start)
    start_http
;;  
stop)
    stop_http
;;  
restart)
    stop_http
    start_http
;;
*)
    echo "Usage : start | stop | restart"
;;
esac

7、加入系統服務:

chmod  a+x  httpd    --增加所屬使用者執行許可權
cp  -arf  httpd  /etc/init.d/  將配置檔案拷貝到該目錄下

8、啟動自己編寫的服務:

systemctl  daemon-reload
systemctl  start  httpd

9、設定開機自啟動:

chkconfig  --add  httpd

10、配置檔案路徑:

/usr/local/apache2/conf/httpd.conf