天天看點

一版完整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

--安裝jpegsrc

# tar -zvxf jpegsrc.v7.tar.gz -C /usr/src/

# cd /usr/src/jpegsrc.v7

# ./configure --prefix=/usr/local/jpeg/ --enable-shared --enable-static

--安裝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

--安裝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

--安裝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

# 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 --把這四句直接加到這個目錄标簽裡

</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