一版完整lamp環境搭建文檔

 

源碼包搭建一個完整的LAMP環境,這個文檔我可是零零散散的花了將近5天的時間,做一步寫一下文檔哦!因爲機器的環境不一樣,安裝過程中可能會出現這樣或那樣的問題,請根據提示消息處理相關問題即可。一共用了17個源碼包.廢話不多說,下面開始。

1、安裝mysql

#tar xvf mysql-5.1.53.tar.gz -C /usr/src
#cd /usr/src/mysql-5.1.53

#./configure --localstatedir=/data/mysql/ --prefix=/usr/local/mysql --enable-assembler --enable-profiling --enable-local-infile --with-charset=utf8 --with-extra-charsets=gbk,gb2312  --with-pthread --with-mysqld-user=mysql --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-low-memory --with-big-tables --sysconfdir=/usr/local/mysql/etc --datadir=/data/mysql/
#make
#make install
#echo /usr/local/mysql/lib/mysql/lib >> /etc/ld.so.conf
#ldconfig
2.安裝apache

 Apache可移植運行時庫(Apache Portable Runtime,APR)和APR的實用庫(APR Utilities、APR-UTILS或者APU)是Apache軟件基金會旗下兩個自主開發和維護的庫,爲Apache的httpd程序所使用。儘管很多的內核開發者要同時涉及開發httpd(即Web服務器)和APR,然而這兩個項目卻是相互獨立的。APR和APU提供了內核函數,這些函數不僅僅只與Web服務相關,對於更加普遍的應用開發也很有用。
APR實際上包含了三個開發包:apr、apr-util以及apr-iconv,每一個開發包分別獨立開發,並擁有自己的版本。
apr開發包位於目錄${APR}\apr下,其中包含了一些通用的開發組件,包括mmap,文件等等,前面已經描述過。
apr-util開發包位於目錄${APR}\apr-util下,該目錄中也是包含了一些常用的開發組件。這些組件與apr目錄下的相比,它們與apache的關係更加密切一些。比如存儲段和存儲段組,加密等
apr-iconv包中的文件主要用於實現iconv編碼。目前的大部分編碼轉換過程都是與本地編碼相關的。在進行轉換之前必須能夠正確地設置本地編碼。因此如果兩個非本地編碼A和B需要轉換,則轉換過程大致爲A->Local以及Local->B或者B->Local以及Local->A。
XPG2 標準中另外定義了一組全新的函式接口ICONV,該接口是一種更廣義的字集轉換系統。也是一個與本地編碼無關的字集轉換系統。APR中也支持這種字集轉換系統,爲此它提供了完整的實現。Apr-iconv正是爲此目的而產生。
--安裝apr-1.3.8.tar.gz
# tar xf apr-1.3.8.tar.gz -C /usr/src/ 
# cd /usr/src/apr-1.3.8/
#./configure --prefix=/usr/local/apr --enable-threads && make && make install

--安裝apr-iconv-1.2.1.tar.gz
# tar xvf apr-iconv-1.2.1.tar.gz -C /usr/src/
# cd /usr/src/apr-iconv-1.2.1/
# ./configure --prefix=/usr/local/apache2 --with=/usr/local/apr/bin/apr-1-config && make && make install    //默認安裝路徑/usr/local/apache2

--安裝apr-util-1.3.9.tar.gz
# tar xf apr-util-1.3.9.tar.gz -C /usr/src/
# cd /usr/src/apr-util-1.3.9/
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config --with-mysql=/usr/local/mysql/ --with-iconv=/usr/local/apache2 && make && make install

--安裝httpd-2.2.9.tar.gz
# tar xvf httpd-2.2.9.tar.gz -C /usr/src
# cd /usr/src/httpd-2.2.9/
# ./configure --enable-so --enable-rewrite --enable-vhost-alias --enable-cgi --enable-info --enable-http --enable-static-ab --enable-static-htpasswd --enable-static-support --enable-proxy --enable-proxy-balancer --enable-deflate --enable-cache --enable-disk-cache --enable-mem-cache  --enable-modules=all --enable-mods-shared=all --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr-util --with-mpm=worker
# make && make install

3.安裝PHP
--安裝freetype
FreeType庫是一個完全免費(開源)的、高質量的且可移植的字體引擎,它提供統一的接口來訪問多種字體格式文件,包括TrueType, OpenType, Type1, CID, CFF, Windows FON/FNT, X11 PCF等。支持單色位圖、反走樣位圖的渲染。FreeType庫是高度模塊化的程序庫,雖然它是使用ANSI C開發,但是採用面向對象的思想,因此,FreeType的用戶可以靈活地對它進行裁剪。
# tar jxvf freetype-2.4.0.tar.bz2 -C /usr/src
# cd /usr/src/freetype-2.4.0
# ./configure --prefix=/usr/local/freetype
# make && make install

--安裝jpegsrc
# tar -zvxf jpegsrc.v7.tar.gz -C /usr/src/
# cd /usr/src/jpegsrc.v7
# ./configure --prefix=/usr/local/jpeg/ --enable-shared --enable-static
# make && make install

--安裝libpng-1.2.41.tar.bz2
# tar -jxvf libpng-1.2.41.tar.bz2 -C /usr/src/
# cd /usr/src/libpng-1.2.41
# ./configure --prefix=/usr/local/libpng && make && make install
# ln -s /usr/local/libpng/include/pngconf.h /usr/include/
# ln -s /usr/local/libpng/include/png.h /usr/include/
--安裝gettext-0.18.tar.gz
Gettext 用於系統的國際化(I18N)和本地化(L10N),可以在編譯程序的時候使用本國語言支持(Native Language Support(NLS)),其可以使程序的輸出使用用戶設置的語言而不是英文.
[gettext-0.18]# ./configure && make && make install
#echo /usr/local/lib >> /etc/ld.so.conf
#ldconfig

--安裝fontconfig-2.8.0.tar.gz
# tar xvf fontconfig-2.8.0.tar.gz -C /usr/src
# cd /usr/src/fontconfig-2.8.0
# ./configure  --prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype/bin/freetype-config && make && make install


--安裝 gd-2.0.35.tar.gz
# tar zxvf gd-2.0.35.tar.gz -C /usr/src/
# cd /usr/src/gd-2.0.35
# ./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype  --with-fontconfig=/usr/local/fontconfig
# make && make install

 

--安裝mcrypt-2.6.6.tar.gz
# tar xvf mcrypt-2.6.6.tar.gz -C /usr/src/
# cd /usr/src/mcrypt-2.6.6/
# ./configure && make && make install

 

--安裝php-5.3.3.tar.bz2
# tar xvf php-5.3.3.tar.bz2 -C /usr/src/
# cd /usr/src/php-5.3.3
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mod-charset --enable-sigchild --enable-magic-quotes --enable-libgcc  --with-zlib --enable-bcmath --enable-calendar --enable-dba --enable-exif --enable-ftp --enable-gd-native-ttf --enable-gd-jis-conv --enable-intl --enable-mbstring  --enable-pcntl --enable-shmop --enable-soap --enable-sqlite-utf8 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --enable-zip --with-zlib-dir  --with-gettext=/usr/local  --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/libpng   --with-mcrypt  //如編譯中途提示找不到icu配置文件,執行  yum install libicu libicu-devel -y
# make && make install

# cp php.ini-production /usr/local/php/lib/php.ini

禁止php腳本執行系統指令

# vim /usr/local/lib/php.ini
disable_functions = passthru,shell_exec,system,proc_nice,proc_open,proc_terminate,exec,popen

4、apache相關設置
apache添加php支持
AddType application/x-http-php .php

網站安全設定,對敏感網頁加密,
# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/data/webroot01"
    ServerName 10.0.10.9
    ErrorLog "logs/10.0.10.9-error_log"
    CustomLog "logs/10.0.10.9-access_log" common

<Directory "/data/webroot01">
    AllowOverride None
    Options FollowSymLinks
    Order allow,deny
    Allow from all
</Directory>
<Directory "/data/webroot01/phpmyadmin"> //網頁加密
Options FollowSymLinks 
AllowOverride None  --none不用改成all
Order allow,deny 
Allow from all 
authname "please input your username and password! @_@"     
authtype basic
authuserfile /usr/local/apache2/conf/userpasswd
require valid-user --把這四句直接加到這個目錄標籤裏
</Directory>

</VirtualHost>

# htpasswd -c /usr/local/apache2/conf/userpasswd  xuwenadmin     //生成可以訪問/data/webroot01/phpmyadmin的用戶及密碼

# /usr/local/apache2/bin/apachectl -k start --重啓後,驗證,也可以

若啓動過程中報如下錯誤,說明打開了selinux
httpd: Syntax error on line 114 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied

查看selinux運行狀態:
# getenforce
Enforcing
# sestatus  
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 21
Policy from config file:        targeted

查看系統默認對libphp5.so(RPM包的libphp5.so,然後在源碼包上打上一樣的標記就搞定)打上什麼樣的標記
#semanage fcontext -l | grep php
/usr/lib(64)?/php/modules/.+\.so                   regular file       system_u:object_r:textrel_shlib_t:s0
/usr/lib(64)?/httpd/modules/libphp5\.so            regular file       system_u:object_r:textrel_shlib_t:s0

修改libphp5.so是安全上下文:
# chcon -R -t textrel_shlib_t /usr/local/apache2/modules/libphp5.so                  //restorecon -RFv /webroot/ 將此目錄下的文件及文件夾恢復到默認標記
# semanage fcontext -a -t textrel_shlib_t /usr/local/apache2/modules/libphp5.so
# /usr/local/apache2/bin/apachectl -k restart


日誌切割
# tar xvf cronolog-1.6.2.tar.gz -C /usr/src/

# cd /usr/src/cronolog-1.6.2/

編譯安裝
# ./configure --prefix=/usr/local/cronolog ;make ;make install

vim /usr/local/apache2/conf/extra/http-vhost.conf

修改:
CustomLog logs/access_log combined
改成:
CustomLog "|/usr/local/cronolog/sbin/cronolog /usr/local/apache2/logs/%Y/%m/%d/access_log" combined
--注意格式不要寫錯

重啓apache後,過幾秒,或者訪問一下apache

就會在/usr/local/apache2/logs下產生了切割日誌
# ls /usr/local/apache2/logs/* -R
/usr/local/apache2/logs/10.0.10.9-error_log  /usr/local/apache2/logs/error_log
/usr/local/apache2/logs/access_log           /usr/local/apache2/logs/httpd.pid
/usr/local/apache2/logs/cgisock.2045

/usr/local/apache2/logs/2011:
11

/usr/local/apache2/logs/2011/11:
26

/usr/local/apache2/logs/2011/11/26:
access_log


到此結束,終於大功造成……淚滿面……

 

文檔整理人:石軍    QQ:295568080   E-mail:[email protected]
交流羣:我們都是挨踢人 167125978

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