安装编译LAMP平台
LAMP用处广泛,在LAMP平台中源码包安装httpd、php、mysql至关重要,它能解决一些rpm包没有编译但是我们又需要的安装的配置,并且可以自己手动编译自己需要的安装内容,避免了一些不必要的安装!
安装编译LAMP平台
安装次序:httpdàMySQLàPHP
由于httpd是有C语言开发的,且有众多不同版本,为了能让httpd运行在不同主机上,引入了一个类似虚拟机的工具,让httpd在此工具上运行,因此要想安装httpd就必须要安装此工具。
Apache给我们提供了一个这样的工具:apr,apr-util
前提:
httpd:2.4.4 + MySQL:5.6.10 + php:5.4.13
由于这儿用到的httpd是2.4.3版本的,相对应的apr,apr-util也要是较新的!
RedHat一般都提供了apr,apr-util平台,检查版本是否过低,1.4以上的版本即可!如果版本过低,可以用rpm 进行升级,或者在找个路径用源代码编译,这里使用的是源代码方式!
安装次序:apràapr-utilàhttpdàMySQLàphpàXCache
将编译文件放在/usr/local/
编译安装apr:
下载apr-1.4.6.tar.bz2到本地目录下(这里为root的家目录)
# tar –xf apr-1.4.6.tar.bz2
# cd apr-1.4.6
# ./configure --prefix=/urs/local/apr
# make
# make install
安装成功!
编译安装apr-util:
因为apr-util依赖于apr,所以在编译过程中要指明apr所在的路径。
# tar -xf apr-util-1.4.1.tar.bz2
# cd apr-util-1.4.1
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make
# make install
这两个包的编译都不需要修改其配置文件,因为在编译httpd时直接指向两者的安装路径,httpd就会直接去找相关的内容来用!
编译安装httpd:
在编译前,先介绍几个相关的编译特性
--prefix=/...:安装路径
--with-apr=/...:告诉其依赖包的路径
--sysconfdir=/...:配置文件安装路径 --enable-modules=most:启用大多数模块
--enable-mods-shared=MODULE-LIST:是不是启用共享模块(all,most,few,reallyall)
--enable-so:支持动态共享模块(默认支持,如果不支持httpd无法和php进行交互)
--enable-ssl:启用ssl功能(不然无法启用https功能)
--enable-cgi:以cgi的方式进行交互
--enable-cgid:在(worker,event)启用
--enable-rewrite:支持URL重写
httpd还依赖于pcre-devel,安装前先查看pcre-devel是否已经安装。
# yum install pcre-devel –y
# tar –xf httpd-2.4.4.tar.bz2
# cd httpd-2.4.4
#./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-cgid --enable-cgi --enable-ssl --enable-rewirte --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
# make
# make install
编译安装好httpd如何启动呢?rpm包启动服务可以用命令service httpd start,而编译安装的httpd在其安装路径下/usr/local/apache/bin/有个apachectl脚本,执行此脚本即可打开其服务!
因为httpd受selinux管理!在启动前先关掉selinux!
# setenforce 0
# netstat –tnlp
查看是否有80端口在监听
# cd
开启httpd
# /usr/local/apache/bin/apachectl start
# netstat –tnlp
每个进程都有一个pid文件,而pid文件一般放在/var/run下,而编译安装的httpd则将其在了/usr/local/apache/logs下了,为了便于管理,我们也放在/var/run下,如何放呢?在httpd的配置文件中加上pid存放路径即可!在编译源文件时,一般将其备份一份,以免不时之需!在修改之前先关掉httpd
# /usr/local/apache/bin/apachectl stop
# cd /etc/httpd
# cp httpd.conf httpd.conf.bak
# vim httpd.conf
# /usr/local/apache/bin/apachectl start
# cd /var/run
# ls
httpd开启后在/var/run生成了httpd.pid文件,修改正确!我们发现每次要重启,关闭httpd都要输入很长的一段命令很是不爽,我们可以编写一个脚本让它向rpm包一样,能通过service httpd start来开启!
在/etc/rc.d/init.d/创建一个httpd文件
# vim /etc/rc.d/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
##############################################################################
# chown +x /etc/rc.d/init.d/httpd
将httpd加载到服务列表中
# chkconfig --add httpd
apache目录下bin中的命令有些还不能用,如何能实现?
在/etc/profile.d/创建一个以.sh结尾的文件
# vim /etc/profile.d/httpd.sh
重新登录,httpd的相关命令就可以执行了!
测试结果: