標籤:
CentOS 6.5下源碼安裝LAMP(Linux+Apache+Mysql+Php)環境
一.系統內容:
Linux系統版本: CentOS release 6.5
Apache版本: httpd-2.2.24
PHP 版本: php-5.6.11
二.安裝前準備:
1.查看是否安裝GCC ,GCC-C++編譯器,如果沒有則進行安裝:
查看是否安裝的命令:
#gcc –v
若未安裝在伺服器連網情況下可以使用下列命令安裝:
#yum install gcc
#yum install gcc-c++
2.查看和卸載預設的低版本環境(系統安裝時內建的rpm包安裝環境)
檢查是否安裝以apache為例:
#rpm –qa | grep httpd
出現的情況說明已安裝:
3.卸載低版本環境:
#rpm –e httpd*
#rpm –e php* (有時可能需要先卸載mysql,再卸載php)
#rpm –e mysql*
三.相關庫檔案與外掛程式準備:
1.在安裝PHP之前需要安裝最新的版本庫檔案:
Libxml2,libmcrypt,gd2 (gd2庫是為了讓PHP5支援GIF,PNG和JPG等圖片格式,所以在安裝gd2之前還需要先安裝 zlib,libpng,freetype和jpegsrc等庫檔案)
四.安裝LAMP:
1.安裝庫檔案:
a.安裝libxml2 版本:libxml2-2.6.30.tar.gz
# ./configure –prefix=/usr/local/libxml
#make && make install
b.安裝libmcrypt 版本:libmcrypt-2.5.8.tar.gz
#./configure –prefix=/usr/local/libmcrypt
#make && make install
c.安裝zlib 版本:zlib-1.2.3.tar.gz
#./configure
#make &&make install
d.安裝libpng 版本:libpng-1.2.52.tar.gz
#./configure –prefix=/usr/local/libpng
#make && make install
e.安裝jpeg6 版本:jpegsrc.v8b.tar.gz (此軟體安裝時需要手動建立目錄)
#mkdir /usr/local/jpeg6
# mkdir /usr/local/jpeg6/bin
# mkdir /usr/local/jpeg6/lib
# mkdir /usr/local/jpeg6/include
# mkdir /usr/local/jpeg6/man/man1
#./configure –prefix=/usr/local/jpeg6/ --enable-shared –enable-static
#make && make install
f.安裝freetype 版本:freetype-2.3.5.tar.gz
#./configure –prefix=/usr/local/freetype
#make
#make install
g.安裝autoconf 版本:autoconf-2.61.tar.gz
#./configure
#make && make install
h.安裝GD庫 版本:gd-2.0.33.tar.gz
# /configure \
--prefix=/usr/local/gd2/ \
--enable-m4_pattern_allow \
--with-zlib=/usr/local/zlib/ \
--with-jpeg=/usr/local/jpeg6/ \
--with-png=/usr/local/libpng/ \
--with-freetype=/usr/local/freetype/
#make (註:到這一步安裝時一般會出現報錯:)
報錯資訊:
make[2]: *** [gd_png.lo] Error 1
make[2]: Leaving directory `/usr/local/src/gd-2.0.35‘
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/src/gd-2.0.35‘
make: *** [all] Error 2
原因分析與解決方案:
(1)出現此報錯主要因為gd庫檔案中的gd_png.c這個檔案裡的png_h沒有找到。
(2)我們直接#vim gd_png.c 將檔案中的include “png.h”改為 include “/usr/local/libpng/include/png.h”就可以解決該問題,/usr/local/libpng/為先前的libpng的安裝路徑。
(3)更改完成後最後再執行 #make && make install
五.安裝apache,
(1)安裝apache時先安裝所需外掛程式:
#yum install -y openssl mod_ssl
#yum install openssl-devel –y
(2)安裝apr可移植運行庫:
#[httpd-2.2.24]# cd srclib/apr
#[httpd-2.2.24/srclib/apr]# ./configure --prefix=/usr/local/apr
#[httpd-2.2.24/srclib/apr]# make
#[httpd-2.2.24/srclib/apr]# make install
#[httpd-2.2.24/srclib/apr]# cd ../apr-util/
#mkdir /usr/local/apr-util
#[httpd-2.2.24/srclib/apr-util]#./configure--prefix=/usr/local/apr-util --with-apr=/usr/local/apr
#[httpd-2.2.24/srclib/apr-util]# make
#[httpd-2.2.24/srclib/apr-util]# make install
(3)安裝APACHE:
#cd httpd-2.2.24
#./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --enable-dav --enable-dav-fs --enable-modules=most --enable-mods-shared=all --enable-deflate --enable-ssl --with-apr-util=/usr/local/apr-util --enable-so --enable-rewrite --with-mpm=prefork
部分模組功能說明:
a. --enable-mods-shared=all動態載入所有模組
b. --enable-dav --enable-dav-fs部分系統具備檔案上傳功能,因此開啟dav支援。
c. --enable-deflate提供了壓縮功能,一方面節約頻寬,另一方面提高使用者訪問效率
d. --enable-expires 對網站圖片,js,css等內容,提供瀏覽器緩衝的功能。
e. --with-mpm=prefork,選擇prefork模式,prefork提供了比worker模式更穩定的效能。
(4)載入模組
a. mod_ssl.so模組載入操作
#cd http-2.2.24/modules/ssl
#/usr/local/apache/bin/apxs -a –I –c mod_ssl.c -lcrypto -lssl –ldl
b. mod_speling.so模組載入操作(關閉區分大小寫敏感的)
# cd http-2.2.24/modules/ mappers
#/usr/local/ apache/bin/apxs -c -i -a mod_speling.c
(4)編輯apache的設定檔:
4.1 prefork模式設定,在安裝目錄
/usr/local/apache/conf/extra/httpd-mpm.conf下進行編輯:
#vim httpd-mpm.config
將原來預設配置:
<IfModule mpm_prefork_module>
StartServers 5 //伺服器處理序開始子過程數量
MinSpareServers 5 //空閑時伺服器最小進程數
MaxSpareServers 10 //空閑時伺服器最大進程數
MaxRequestWorkers 250 //允許的最大數量的伺服器處理序
MaxConnectionsPerChild 0 //伺服器處理序最大串連數
</IfModule>
更改為如下:
<IfModule mpm_prefork_module>
ServerLimit 20000 //設定為兩萬讓MaxClient支援更多的進程
StartServers 20
MinSpareServers 20
MaxSpareServers 50
MaxClients 1000
MaxRequestsPerChild 10000 //設定為非0可防止記憶體流失,閑時回收進程數量
</IfModule>
4.2 /usr/local/apache/conf下httpd.conf設定檔修改:
#vim httpd.conf
ServerRoot "/usr/local/apache" //apache的安裝路徑該配置在30行
Listen 80 //配置監聽連接埠為80 該配置在41行附近
LoadModule speling_module modules/mod_speling.so
CheckSpelling On // 關閉大小寫區分 56行附近
LoadModule php5_module modules/libphp5.so //載入PHP解譯器 58行
Addtype plication/x-httpd-php .php .phtml //apache與PHP整合 59行
User apache //啟動apache所使用的使用者
Group apache //啟動apache所使用的使用者所屬的使用者組
ServerName localhost:80 //預設伺服器和連接埠 106行附近
123 <Directory /> // apache的根目錄存取權限
124 Options none
125 AllowOverride None
126 Order deny,allow
127 allow from all
128 </Directory>
<Directory "/www"> //apache的預設根目錄與存取權限設定
153 Options none
165 Order allow,deny
166 Allow from all
167
168 </Directory>
174 <IfModule dir_module> //預設首頁配置174---176行
175 DirectoryIndex index.html index.php
176 </IfModule>
182 <FilesMatch "^\.ht"> //.ht檔案訪問設定,預設配置既可,預設可訪問
183 Order allow,deny
184 Deny from all
185 Satisfy All
186 </FilesMatch>
195 ErrorLog "logs/error_log" //錯誤記錄檔目錄配置路徑
386 Include conf/extra/httpd-mpm.conf //啟用MPM模組
404 Include conf/extra/httpd-vhosts.conf//啟用虛擬機器主機配置
416 Include conf/extra/httpd-ssl.conf //啟用認證支援
4.3 SSL配置/usr/local/apache/conf/extra/httpd-ssl.conf
#vim httpd-ssl.conf
37 Listen 443 //啟用HTTPS所使用的443連接埠
78 DocumentRoot "/www" //需要使用HTTPS協議傳輸檔案路徑
79 ServerName localhost:443 //所有網域名稱都跳轉443
80 ServerAdmin [email protected]
81 ErrorLog "/usr/local/apache/logs/error_log"
82 TransferLog "/usr/local/apache/logs/access_log"
(註:每行前的數字為所在設定檔中行數)
未完待續--------------
CentOS 6.5下源碼安裝LAMP(Linux+Apache+Mysql+Php)環境