你们以前听说过LAMP吗? 我会在这里简单的描述一下其工作原理,以及实现的过程。LAMP是一种平台,也是一种架构。我们了解,在web服务器中,有一个httpd进程,但这个进程仅能解释静态内容(网页文件,图片,各种CSS样式文件等)。若有一个动态文件,例:index.php ,则httpd无法执行,因此就需要使用php解释器实现这项功能。让httpd与php交互,将动态内容调用php解释器解析为静态内容交给httpd进程。而我们大多数请求的内容会有许多数据,因此,还需要一个数据库服务器来实现数据的管理。简单说,LAMP平台即为: httpd+php+mysql,三台服务器组成的平台。
我们这里演示完全手动编译配置LAMP,编译的版本为httpd 2.4.4 + mysql-5.5.28 + php-5.4.13,可以在官方网站下载其各个软件包(使用通用二进制安装mysql)。
 
一、准备软件源码包
   1、在编译安装http之前需要先将apr和apr-util升级,升级的两种方式:rpm包直接升级或编译安装新版本的apr,apr-util。我在这里下载编译安装新版本的源码apr-1.4.6.tar.bz2,  apr-util-1.5.2.tar.bz2。
   2、下载http的源码包,httpd-2.4.4.tar.bz2
   3、下载mysql的源码包,mysql-5.5.28-linux2.6-i686.tar.gz
   4、下载php的源码包,php-5.4.13.tar.bz2 (若需要php支持mcrypt扩展,则还需要下载安装两个rpm包:libmcrypt-2.5.7-5.el5.i386.rpm,libmcrypt-devel-2.5.7-5.el5.i386.rpm。我这里直接下载安装)
   5、下载php加速器:xche的源码包,xcache-3.0.1.tar.gz
 
二、前提环境
   1、基于Redhat5的虚拟机
   2、配置好yum仓库
   3、关闭selinux
      # setenforce 0
   4、将系统时间与硬件时间同步
     # hwclock -s
   5、准备好安装环境(Development Libraries)
      # yum groupinstall "Development Libraries"
 
三、详细过程
   1、编译安装apr
  【先解压缩,在解压后的源码目录中安装,编译安装三步骤:./configure,make,make install】
 
 
 
   2、编译安装apr-util
   【解压缩以及编译安装三步骤】
 
 
 
   3、编译安装httpd
 
   【由于httpd编译过程中依赖 pcre-devel软件包,因此需先将其安装】
 
 
 
   【解压缩,手动编译】
 
 
 
(# ./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)
 
 
   【我们先可以根据二进制启动一下服务,并打开浏览器访问。此时已能工作】
 

   【将http进程的pid文件放到/var/run下(默认编译后在apache/logs下)】

   (编辑主配置文件后,启动服务验证即可)
     #  vim  /etc/httpd/httpd.conf 
 

 【为httpd提供服务脚本】
  我这里已经提供好一个脚本,我们只需要创建脚本文件将其复制过去就行。
 
 
  
  1. #  vim  /etc/init.d/httpd  
  2. #!/bin/bash  
  3. #  
  4. # httpd        Startup script for the Apache HTTP Server  
  5. #  
  6. # chkconfig: - 85 15  
  7. # description: Apache is a World Wide Web server.  It is used to serve \  
  8. #        HTML files and CGI.  
  9. # processname: httpd  
  10. # config: /etc/httpd/conf/httpd.conf  
  11. # config: /etc/sysconfig/httpd  
  12. # pidfile: /var/run/httpd.pid  
  13. # Source function library.  
  14. . /etc/rc.d/init.d/functions  
  15. if [ -f /etc/sysconfig/httpd ]; then  
  16.         . /etc/sysconfig/httpd  
  17. fi  
  18. # Start httpd in the C locale by default.  
  19. HTTPD_LANG=${HTTPD_LANG-"C"}  
  20. # This will prevent initlog from swallowing up a pass-phrase prompt if  
  21. # mod_ssl needs a pass-phrase from the user.  
  22. INITLOG_ARGS=""  
  23. # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server  
  24. # with the thread-based "worker" MPM; BE WARNED that some modules may not  
  25. # work correctly with a thread-based MPM; notably PHP will refuse to start.  
  26. # Path to the apachectl script, server binary, and short-form for messages.  
  27. apachectl=/usr/local/apache/bin/apachectl  
  28. httpd=${HTTPD-/usr/local/apache/bin/httpd}  
  29. prog=httpd  
  30. pidfile=${PIDFILE-/var/run/httpd.pid}  
  31. lockfile=${LOCKFILE-/var/lock/subsys/httpd}  
  32. RETVAL=0 
  33. start() {  
  34.         echo -n $"Starting $prog: " 
  35.         LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS  
  36.         RETVAL=$?  
  37.         echo  
  38.         [ $RETVAL = 0 ] && touch ${lockfile}  
  39.         return $RETVAL  
  40. }  
  41. stop() {  
  42. echo -n $"Stopping $prog: " 
  43. killproc -p ${pidfile} -d 10 $httpd  
  44. RETVAL=$?  
  45. echo  
  46. [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}  
  47. }  
  48. reload() {  
  49.     echo -n $"Reloading $prog: " 
  50.     if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then  
  51.         RETVAL=$?  
  52.         echo $"not reloading due to configuration syntax error" 
  53.         failure $"not reloading $httpd due to configuration syntax error" 
  54.     else 
  55.         killproc -p ${pidfile} $httpd -HUP  
  56.         RETVAL=$?  
  57.     fi  
  58.     echo  
  59. }  
  60. # See how we were called.  
  61. case "$1" in 
  62.   start)  
  63. start  
  64. ;;  
  65.   stop)  
  66. stop  
  67. ;;  
  68.   status)  
  69.         status -p ${pidfile} $httpd  
  70. RETVAL=$?  
  71. ;;  
  72.   restart)  
  73. stop  
  74. start  
  75. ;;  
  76.   condrestart)  
  77. if [ -f ${pidfile} ] ; then  
  78. stop  
  79. start  
  80. fi  
  81. ;;  
  82.   reload)  
  83.         reload  
  84. ;;  
  85.   graceful|help|configtest|fullstatus)  
  86. $apachectl $@  
  87. RETVAL=$?  
  88. ;;  
  89.   *)  
  90. echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}" 
  91. exit 1 
  92. esac  
  93. exit $RETVAL  
#  chmod +x /etc/init.d/httpd    -->  加权限
#  chkconfig  --add  httpd   -->  加入服务列表
 
 
4、编译安装mysql
由于使用通用二进制安装,则可直接将压缩包解压至/usr/local使用。
 
【准备好一个逻辑卷,并创建一个单独的目录/mydata/data,将逻辑卷挂载至/mydata即可】
 
【初始化mysql要使用mysql用户和mysql组,因此,我们需自己创建】
 
初始化mysql
 
   

【提供主配置文件以及sysv服务的脚本】  
 

【添加环境变量,指定二进制文件的所在路径】
 #  vim  /etc/profile.d/mysql.sh

 
【启动服务测试使用】
 
 
5、编译安装php-5.4.13
【安装两个rpm包】
     #  rpm -ivh libmcrypt-2.5.7-5.el5.i386.rpm libmcrypt-devel-2.5.7-5.el5.i386.rpm 
【解压缩,编译安装】
     #  cd php-5.4.13
     # ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts
     #  make
     #  make install
【提供配置文件】
 
   

 

【重启httpd,测试php是否成功】
 
   

 

 
6、编译安装xcache,为php加速
【解压缩,编译】
 
 

【配置文件】
 
 

 

【重启httpd,打开web页面验证】
      #  service httpd restart
 
这样就实现了httpd,php,mysql的结合 --> LAMP平台。必须注意,要先安装mysql载安装php,因为php的编译需要mysql的安装路径。