centos 6 編譯安裝LAMP

搭建環境:Centos 6.8,httpd2.4.18,mysql 5.6.23,php 5.6.17  

一、前期準備

  請參考LNMP前期準備和mysql安裝請參考:http://zhoufan.blog.51cto.com/4278592/1793394

二、httpd安裝

安裝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 --with-apr=/usr/local/apr
make && make install

安裝httpd

cd httpd-2.4.18
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event
make && make install

編譯安裝部分參數說明

--enable-so #支持DSO動態裝載模塊
--enable-ssl #要編譯啓用ssl模塊(前提是需要安裝openssl-devel)
--enable-cgi #啓用CGI模塊(默認就啓用)
--enable-rewrite #URL重寫(支持URL重寫)
--with-zlib #這是一個壓縮庫(專用於網絡傳輸)
--with-pcre #使用增強的perl正則表達式分析工具(使用這項需要安裝pcre-devel,pcre:正則表達式分析器)
--with-apr=/usr/local/apr #指明apr的目錄(若apr在特殊路徑下)
--with-apr-util=/usr/local/apr-util/ #指明apr-util路徑(若apr-util在特殊路徑下
)
--enable-mpms-shared=all #把所有的mpm模塊都編譯進來而且是共享模塊
--with-mpm=work #默認使用的mpm模塊
--enable-modules=most(all) #還有很多其他模塊,其他的動態可裝載模塊需要

測試httpd配置是否正常

/usr/local/apache/bin/apachectl -t

設置httpd服務和開機啓動項

cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
vim /etc/rc.d/init.d/httpd
    #chkconfig: 35 61 61
    #description:Apache
chkconfig --add httpd
chkconfig httpd on

三、php編譯安裝

前期準備(補充安裝,--with-xsl使用)

yum install libxslt-devel

安裝php

tar xf php-5.6.17.tar.gz
cd php-5.6.17
 ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem -disable-inline-optimization --enable-mbregex --enable-mbstring --with-gd --enable-gd-native-ttf --with-mhash --enable-pcntl --enable-sockets --with-mcrypt --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-bz2 --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-maintainer-zts --with-xmlrpc=shared --with-xsl
make ZEND_EXTRA_LIBS='-liconv' 
make install

編譯安裝部分參數說明(很多加載項用途不明,從別處抄襲,前幾位參數還是特別重要的,比如--with-apsx2,httpd和php整合用使用)

--with-mysql=/usr/local/mysql     #MySQL安裝目錄,對mysql的支持
--with-mysqli=/usr/local/mysql/bin/mysql_config  #mysqli擴展技術不僅可以調用MySQL的存儲過程、處理MySQL事務,而且還可以使訪問數據庫工作變得更加穩定。 
--with-apxs2=/usr/local/apache/bin/apxs    #整合apache,apxs功能是使用mod_so中的LoadModule指令,加載指定模塊到 apache,要求 apache 要打開SO模塊
--with-iconv-dir=/usr/local   # 選項指令,用於PHP編譯時指定iconv在系統裏的路徑,否則會掃描默認路徑(與ZEND_EXTRA_LIBS='-liconv')。
--enable-maintainer-zts #編譯成zts模塊,event,worker模式使用
--with-freetype-dir   #打開對freetype字體庫的支持 
--with-jpeg-dir   #打開對jpeg圖片的支持 
--with-png-dir   #打開對png圖片的支持 
--with-zlib-dir   #打開zlib庫的支持,用於http壓縮傳輸
--with-libxml-dir   #打開libxml2庫的支持
--disable-rpath    #關閉額外的運行庫文件 
--enable-bcmath    #打開圖片大小調整,用到zabbix監控的時候用到了這個模塊
--enable-sysvsem  #這樣就使得你的PHP系統可以處理相關的IPC函數了。
--enable-inline-optimization  #優化線程
--with-curl    #打開curl瀏覽工具的支持 
--with-curlwrappers    #運用curl工具打開url流 
--enable-mbregex
--enable-fpm           #支持PHP-fpm,早期版本需要補丁後纔有這個參數,CGI方式安裝的啓動程序
--enable-mbstring   #多字節,字符串的支持 
--with-mcrypt     #mcrypt算法擴展
--with-mhash      #mhash算法擴展
--with-gd          #打開gd庫的支持 
--enable-gd-native-ttf   #支持TrueType字符串函數庫
--with-openssl      #openssl的支持,加密傳輸https時用到的
--enable-pcntl   #freeTDS需要用到的,可能是鏈接mssql纔用到
--enable-sockets     #打開sockets支持
--with-xmlrpc    #打開xml-rpc的c語言 
--enable-zip   #打開對zip的支持 
--enable-ftp   #打開ftp的支持 
--with-bz2    #打開對bz2文件的支持        
--without-iconv  #關閉iconv函數,字符集間的轉換 
--with-ttf     #打開freetype1.*的支持,可以不加了 
--with-xsl     #打開XSLT文件支持,擴展了libXML2庫,需要libxslt軟件 
--with-gettext    #打開gnu的gettext支持,編碼庫用到 
--with-pear    #打開pear命令的支持,PHP擴展用的 
--enable-calendar  #打開日曆擴展功能
--enable-exif    #圖片的元數據支持 
--enable-magic-quotes   #魔術引用的支持 
--disable-debug    #關閉調試模式 
--with-mime-magic=/usr/share/file/magic.mime      #魔術頭文件位置
#CGI方式安裝才用的參數 
--enable-fastCGI            #支持fastcgi方式啓動PHP
--enable-force-CGI-redirect        #重定向方式啓動PHP
--with-ncurses         #支持ncurses屏幕繪製以及基於文本終端的圖形互動功能的動態庫
--with-gmp  #應該是支持一種規範
--enable-dbase          #建立DBA作爲共享模塊
--with-pcre-dir=/usr/local/bin/pcre-config    #perl的正則庫案安裝位置
--disable-dmalloc
--with-gdbm      #dba的gdbm支持
--enable-sigchild
--enable-sysvshm
--enable-zend-multibyte         #支持zend的多字節
--enable-wddx
--enable-soap

提供php配置文件

cp php.ini-production /etc/php.ini

修改httpd.conf,使其支持php,並且可以識別index.php結尾作爲首頁

AddType application/x-httpd-php  .php
AddType application/x-httpd-php-source  .phps
DirectoryIndex  index.php  index.html

四、PHP擴展

libevent編譯安裝(libevent是一個基於事件觸發的網絡庫,memcached底層也是使用libevent庫。)

tar xf libevent-2.0.22-stable.tar.gz
cd libevent-2.0.22-stable
./configure --prefix=/usr/local/libevent
make && make install
echo "/usr/local/libevent/lib" > /etc/ld.so.conf.d/libevent.conf
ldconfig

memcached編譯安裝

tar xf memcached-1.4.25.tar.gz
cd memcached-1.4.25
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/
make && make install

編譯memcached開機啓動項(部分設置均在服務腳本中)

vim /etc/rc.d/init.d/memcached
#!/bin/bash
#
# Init file for memcached
#
# chkconfig: - 86 14
# description: Distributed memory caching daemon
#
# processname: memcached
# config: /etc/sysconfig/memcached

. /etc/rc.d/init.d/functions

## Default variables
PORT="11211"
USER="root"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""

RETVAL=0
prog="/usr/local/memcached/bin/memcached"
desc="Distributed memory caching"
lockfile="/var/lock/subsys/memcached"

start() {
        echo -n $"Starting $desc (memcached): "
        daemon $prog -d -p $PORT -u $USER -c $MAXCONN -m $CACHESIZE 
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch $lockfile
        return $RETVAL
}

stop() {
        echo -n $"Shutting down $desc (memcached): "
        killproc $prog
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f $lockfile
        return $RETVAL
}

restart() {
        stop
        start
}

reload() {
        echo -n $"Reloading $desc ($prog): "
        killproc $prog -HUP
        RETVAL=$?
        echo
        return $RETVAL
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  condrestart)
        [ -e $lockfile ] && restart
        RETVAL=$?
        ;;       
  reload)
        reload
        ;;
  status)
        status $prog
        RETVAL=$?
        ;;
   *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        RETVAL=1
esac

exit $RETVAL
chmod +x /etc/rc.d/init.d/memcached 
chkconfig --add memcached
service memcached start

memcached部分參數說明

-l <ip_addr>:指定進程監聽的地址;
-d: 以服務模式運行;
-u <username>:以指定的用戶身份運行memcached進程;
-m <num>:用於緩存數據的最大內存空間,單位爲MB,默認爲64MB;
-c <num>:最大支持的併發連接數,默認爲1024;
-p <num>: 指定監聽的TCP端口,默認爲11211;
-U <num>:指定監聽的UDP端口,默認爲11211,0表示關閉UDP端口;
-t <threads>:用於處理入站請求的最大線程數,僅在memcached編譯時開啓了支持線程纔有效;
-f <num>:設定Slab Allocator定義預先分配內存空間大小固定的塊時使用的增長因子;
-M:當內存空間不夠使用時返回錯誤信息,而不是按LRU算法利用空間;
-n: 指定最小的slab chunk大小;單位是字節;
-S: 啓用sasl進行用戶認證;

freetds編譯安裝(用於php連接mssql)

tar xf freetds-1.00.11.tar.gz
cd freetds-1.00.11
./configure --prefix=/usr/local/freetds --with-tdsver=7.3 --enable-msdblib --with-gnu-ld --enable-shared --enable-static
make && make install
cd /usr/local/src/php-5.6.17/ext/mssql/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-mssql=/usr/local/freetds/
make && make install

--with-tdsver=7.3說明,具體說明參照:

http://www.freetds.org/userguide/choosingtdsprotocol.htm#TAB.PROTOCOL.BY.PRODUCT

wKiom1eXNBrCzsr4AAB2YE_enNA904.png

安裝php支持memcache擴展模塊

tar zxvf memcache-2.2.7.tgz 
cd memcache-2.2.7
/usr/local/php/bin/phpize 
./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zib-dir
make && make install

修改php.ini,增加freetds和memcache功能

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20131226/"
extension=mssql.so
mssql.charset="GBK"
extension=memcache.so

重啓httpd使生效

service httpd restart

編寫php測試頁面

<?php
      $link = mysql_connect('ip address','user','passwd');
      if ($link)
        echo "MySQL Success...";
      else
        echo "MySQL Failure...";
        mysql_close();
        $conn=mssql_connect('ip address','user','passwd');
        if($conn)
                echo"MSSQL Sucess...";
        else
                echo"MSSQL Failure...";
      mssql_close();
      phpinfo();
?>

測試可正常使用

wKioL1eXO0jwle8ZAABZSzaWqTU342.png

wKioL1eXNzKAOJluAAAnwnABSMA265.png

wKioL1eXNzLTOjf5AAAyHfm3lQw710.png

五、後記

  本篇博文拖了好久才寫出來,其實LAMP編譯安裝還是挺簡單的,只是httpd和php的模塊化整合搞了好久(./configure具體配置不知何用),計劃用於公司的IPOS系統測試使用,後面幾篇博文計劃httpd.conf,php.ini,nginx.conf配置說明。web服務器的搭建還是得熟練點,畢竟Linux使用最多的東西。



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