您的位置:首页 > 其它

一步一步源码编译最新版LAMP平台(一)

2015-05-31 00:51 429 查看
LAMP平台作为互联网上使用最多的网站平台,熟练的搭建是每个linux系统工程师必备的技能,但是由于每个项目或者公司的需求,官方提供的Rpm包在功能和特性上不能满足每个人,所以我们需要自己根据自己的需要编码编译。

准备环境:vmware workstation 10 redhat 5.10 x86_64
下载各版本最新的源码包,如下:




安装linux,配置本地光盘yum源,配置ip 此处省略1000字......
上传软件包至/usr/local/src目录下,第三方下载的软件一般放在这里,方便管理
因为是源码编译,所以需要安装开发环境,所以安装开发组件
yum groupinstall "Development Libraries" "Development Tools"

下面首先安装web服务器因为安装apache需要apr,apr-util,pcre,所以需要先安装他们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已经安装完成,大家可以启动下,用浏览器可以看到



本文出自 “Linux is belong to you” 博客,请务必保留此出处http://jwh5566.blog.51cto.com/7394620/1656742
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: