一步一步源碼編譯最新版LAMP平臺(一)

LAMP平臺做爲互聯網上使用最多的網站平臺,熟練的搭建是每一個linux系統工程師必備的技能,可是因爲每一個項目或者公司的需求,官方提供的Rpm包在功能和特性上不能知足每一個人,因此咱們須要本身根據本身的須要編碼編譯。java


準備環境:vmware workstation 10linux

                 redhat 5.10 x86_64 
web

下載各版本最新的源碼包,以下:
apache

wKioL1Vp7xSjMAKkAAE5Yg6sGYM096.jpg


安裝linux,配置本地光盤yum源,配置ipvim

        此處省略1000字......瀏覽器


上傳軟件包至/usr/local/src目錄下,第三方下載的軟件通常放在這裏,方便管理bash


由於是源碼編譯,因此須要安裝開發環境,因此安裝開發組件服務器

yum groupinstall "Development Libraries" "Development Tools"


下面首先安裝web服務器jvm

由於安裝apache須要apr,apr-util,pcre,因此須要先安裝他們ide

apr提供了apache的運行時環境,相似於java的jvm,apr-util和pcre則提供了apache須要的庫文件


安裝apr

tar xf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure  --prefix=/usr/local/apr
make && make install


安裝apr-util

tar xf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure  --prefix=/usr/local/apr-util
make && make install


安裝pcre

tar xf pcre-8.36.tar.gz
cd pcre-8.36
./configure
make && make install


安裝完成以後就能夠安裝apache了

tar xf httpd-2.4.12.tar.gz
cd httpd-2.4.12

./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewrite 
--enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most
 --enable-mpms-shared=all --with-included-apr --with-pcre=/usr/local/bin/pcre-config 
#解釋下apache的配置選項
#--enable-so 開啓動態加載模塊
#--enable-rewrite  開啓url重寫
#--enable-cgi 開啓prefork模式的mpm,支持cgi
#--enable-cgid 開啓worker和event線程模式mpm,支持fastcgi
#--enable-modules=most 將大多數的模塊編譯
#--enable-mods-shared=most 將大多數的模塊編譯成共享模塊
#--enable-mpms-shared=all 開啓全部的mpm模式,apache 2.4默認啓動event模式
#--with-included-apr
這裏注意下,原本我使用--with-apr和--with-apr-util,可是在編譯apache的時候出錯,網上查了下,
說是沒找到apr,因此使用--with-included-apr得方式,使用這種方式要注意,須要將apr和apr-util
移動到srclib目錄下面,這樣在編譯apache的時候就不會有問題。
    cd httpd-2.4.12
    mv ../apr-1.5.2 srclib/apr
    mv ../apr-util-1.5.4 srclib/apr-util
配置完成會後就能夠編譯和安裝了
make && make install


apache默認的pid文件在logs目錄下,不符合系統的風格,因此咱們修改/etc/httpd/httpd.conf

將pid的目錄修改成/var/run/httpd.pid

在/etc/httpd/httpd.conf中添加一行


PidFile 「/var/run/httpd.pid」


安裝完apache以後,就能夠啓動apache,可是因爲編譯安裝不會提供SysV風格的啓動腳本,因此咱們還須要本身提供

在/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/httpd

加入服務列表:

# chkconfig --add httpd
# chkconfig --level 35 on


將apache的bin目錄加入PATH變量

vim /etc/profile.d/httpd.sh
    export PATH=$PATH:/usr/local/apache/bin

至此apache已經安裝完成,你們能夠啓動下,用瀏覽器能夠看到

wKioL1Vp-O7AT_3VAACkbpk6ZPo711.jpg

相關文章
相關標籤/搜索