Linux下Apache的安裝與配置

來源:互聯網
上載者:User

標籤:not   img   ssl   新版本   idt   sel   target   時間   許可權   

本文安裝的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
(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
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完成後重新登入就可以了。推薦使用第二種方法

三、驗證

安裝成功!

Ubuntu Server 14.04 安裝Web伺服器(Linux+Apache+MySQL+PHP)  http://www.linuxidc.com/Linux/2015-06/119061.htm

Linux下安裝配置PHP環境(Apache2)  http://www.linuxidc.com/Linux/2015-05/118062.htm

Ubuntu 13.04 安裝 LAMP\Vsftpd\Webmin\phpMyAdmin 服務及設定 http://www.linuxidc.com/Linux/2013-06/86250.htm

CentOS 5.9下編譯安裝LAMP(Apache 2.2.44+MySQL 5.6.10+PHP 5.4.12) http://www.linuxidc.com/Linux/2013-03/80333p3.htm

RedHat 5.4下Web伺服器架構之源碼構建LAMP環境及應用PHPWind http://www.linuxidc.com/Linux/2012-10/72484p2.htm

Apache 的詳細介紹:請點這裡
Apache 的:請點這裡

本文永久更新連結地址:http://www.linuxidc.com/Linux/2016-04/130079.htm

Linux下Apache的安裝與配置

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.