一步一步源码编译最新版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

相关文章
相关标签/搜索