LAMP - 功能強大的平臺

 

你們以前聽說過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的安裝路徑。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章