实验目的:搭建LAMP环境
实验环境:RHEL61_64
Apache:http-2.2.19
PHP:php-5.2.17
Mysql:mysql-cluster-7.1.15a

环境所需软件包:
apr-1.3.8.tar.gz                    <- 于 tomcat 其他中间间 API 接口
apr-iconv-1.2.1.tar.gz            <- 于 tomcat 其他中间间 API 接口
libiconv-1.13.tar.gz            <- 其他软件依赖库
apr-util-1.3.9.tar.gz            <- 于 tomcat 其他中间间 API 接口
pcre                                     <- 字符控制,perl 正则表达式支持
openssl-1.0.0e.tar.gz
httpd-2.2.19.tar.gz
mysql-cluster-7.1.15a
freetype-2.1.10.tar.gz            <- 字符处理库
libevent-1.4.11-stable.tar.gz    <- 事件处理库
jpeg-8c.tar.gz                <- jpg 图片处理
libpng-1.2.37.tar.gz            <-图片处理库
xpm-3.4k.tar.gz
gd-2.0.36RC1.tar.gz            <- 应用程序,水印图片输出软件
libmcrypt-2.5.8.tar.bz2         <- 数据加密库
mhash-0.9.9.9.tar.bz2         <- 哈希加密
mcrypt-2.6.6.tar.gz            <- 加密库
ruby-1.8.6.tar.gz
php-5.2.17
libxml2                    <- xml 支持
rrdtool                    <- 图形输出软件


php                     SAPI modules
        与 web server   php与web服务器连接器                                  mysql
        apache2.X        --with-apxs2
        apache1.X        --with-apxs
        nginx        --enable-fastcgi --enable-force-cgi-redirect          php.ini
        tux            --with-tux=MODULEDIR
        Caudium        --with-caudium
        thttpd        --with-thttpd=        

实验前准备:为保证实验成功,删除以前的相关文件

实验步骤:
整个软件包安装过程大致遵循php最后一个编译的原则

1.tomcat连接器软件包(arp-*)

apr-1.3.8.tar.gz
./configure --enable-threads --disable-ipv6
安装成功后,出现一下提示:
----------------------------------------------------------------------                     
Libraries have been installed in:                                                          
   /usr/local/apr/lib
在以后的软件包安装过程中都要注意此提示,目的是提醒该软件包库的位置
接下来,将此路径写入/etc/ld.so.config.d/lamp.conf
然后执行ldconfig命令,将库文件加入库缓存/etc/ld.so.cache中;

检查是否被放入库缓存方法:
strings /etc/ld.so.cache|grep 库名字
--------------------------------------------------------
yum install -y libuuid-devel
apr-iconv-1.2.1.tar.gz
 ./configure --prefix=/usr/local/apr --with-apr=/usr/local/apr/bin/apr-1-config
--------------------------------------------------------
libiconv-1.13.tar.gz
./configure --enable-static=yes
apr-util-1.3.9.tar.gz
./configure --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-iconv=apr-iconv-1.2.1
   --with-mysql=/usr/local/mysql --with-iconv=/usr/local
-===========================================================================
2.编译安装支持正则表达式
pcre    
./configure --enable-rebuild-chartables --enable-utf8 --enable-newline-is-any
             --enable-pcregrep-libz --enable-pcregrep-libbz2

============================================================================
3.编译安装apache
yum install -y expat*
httpd-2.2.19.tar.gz     (ssl 通过) <- 使用 openssl-devel rpm
./configure --enable-modules=all --enable-mods-shared=all --enable-file-cache --enable-cache --enable-disk-cache --enable-mem-cache --enable-dumpio --enable-echo
 --enable-example --enable-case-filter --enable-case-filter-in --enable-ext-filter --enable-logio --enable-mime-magic --enable-expires --enable-headers
 --enable-usertrack --enable-unique-id --enable-proxy --enable-proxy-connect  --enable-proxy-http  --enable-proxy-ajp --enable-proxy-balancer --enable-ssl
--enable-optional-fn-import --enable-optional-fn-export --enable-static-htpasswd --enable-static-rotatelogs --enable-static-logresolve --enable-static-ab
--enable-http --enable-info --enable-rewrite --enable-so --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr/bin/apu-1-config
--with-pcre=/usr/local --with-mpm=prefork  


注释:
若在RHEL61_64中编译httpd-2.2.9.tar.gz可能需要编译安装openssl
openssl-1.0.0e.tar.gz (可选)
./config --prefix=/usr/local --openssldir=/usr/local/openssl -threads -shared -zlib-dynamic

httpd-2.2.9.tar.gz
./configure  --enable-modules=all --enable-mods-shared=all --enable-file-cache --enable-cache --enable-disk-cache --enable-mem-cache --enable-dumpio --enable-echo --enable-example --enable-case-filter --enable-case-filter-in --enable-ext-filter --enable-logio --enable-mime-magic --enable-expires --enable-headers --enable-ident --enable-unique-id --enable-usertrack --enable-version --enable-proxy --enable-proxy-connect --enable-proxy-ftp --enable-proxy-http --enable-proxy-ajp --enable-proxy-balancer --enable-ssl --enable-static-ab --enable-http --enable-info --enable-cgi --enable-rewrite  --enable-vhost-alias --enable-so --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr/bin/apu-1-config --with-pcre=/usr/local --with-mpm=prefork  --with-ssl=/usr/local/ssl


    \-> prefork -> 进程  (一个非线程型的、预派生的MPM)
     \-> worker -> 线程  (支持混合的多线程多进程的多路处理模块) <- 内存大
==========================================================================
4.检查配置apache,并启动测试apache
  a. 模块是否正确生成
    \->  /usr/local/apache2/modules
        ls /usr/local/apache2/modules/libphp5.so
  b. dso 接口是否正常
    \-> /usr/local/apache2/bin/apxs

  c. 配置测试启动
    配置清单:
           允许目录访问
           定义默认中文环境
           定义虚拟主机
           定义默认打开的主页
           定义错误页面
           版本信息屏蔽
           拷贝启动脚本
           更改相关目录属性为daemon:daemon
    
vim /usr/local/apache2/conf/httpd.conf
修改apache默认管理用户用户组
vi /usr/local/apache2/conf/httpd.conf
user daemon
group daemon
允许目录访问
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
 
定义默认打开的主页
DirectoryIndex index.html    index.php
定义中文环境
Include conf/extra/httpd-languages.conf
DefaultLanguage  zh-CN
LanguagePriority zh-CN  en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv tr zh-TW
定义虚拟主机
Include conf/extra/httpd-vhosts.conf
NameVirtualhost *:80
修改
<VirtualHost *:80>
    DocumentRoot "/www"
    ServerName www.cluster.com
    ErrorLog "logs/www.cluster.com-error_log"
    CustomLog "logs/www.cluster.com-access_log" combined
</VirtualHost>
定义错误页面
Include conf/extra/httpd-multilang-errordoc.conf
 错误代码定义        -> 404-done.tar
        \->  Include conf/extra/httpd-multilang-errordoc.conf
                \-> errorcode 404  /xxx.html

版本信息屏蔽
Include conf/extra/httpd-default.conf
ServerTokens  Prod
拷贝 启动脚本
    \-> service apache start <--- /usr/local/apache2/bin/apachectrl

=========================================================================================
****************编译安装mysql-cluster-7.1.15a 略
=========================================================================================
5.编译安装字体,支持的图片格式软件包

freetype-2.1.10.tar.gz
./configure

libevent-1.4.11-stable.tar.gz

libpng-1.2.37.tar.gz
./configure --with-pkgconfigdir=/usr/lib64/pkgconfig

jpeg-8c.tar.gz
./configure

xpm-3.4k.tar.gz
yum install -y imake
xmkmf -a
make
make install
make install.man


gd-2.0.36RC1.tar.gz        <--- 水印
rpm -q  fontconfig-devel
./configure --with-libiconv-prefix=/usr/local --with-png=/usr/local --with-freetype=/usr/local  --with-jpeg=/usr/local   --with-xpm=/usr/local

=========================================================================================
6.编译安装与加密相关软件包

yum install -y libtool-ltdl.i686
libmcrypt-2.5.8.tar.bz2
./configure --enable-static --enable-dynamic-loading

mhash-0.9.9.9.tar.bz2 
./configure

mcrypt-2.6.6.tar.gz
./configure  --with-libmcrypt-prefix=/usr/local --with-libiconv-prefix=/usr/local

###############不能够编译###########
libxml2-2.7.3.tar.gz
./configure --with-history --enable-ipv6=off
    \--> 测试 yum list 是否正常 <--
###############不能够编译###########

===========================php编译=============================================================
7.编译安装php
php-5.2.17
    yum install -y zlib-devel  libcurl-devel  net-snmp-*

./configure --with-apxs2=/usr/local/apache2/bin/apxs --disable-ipv6 --with-libxml-dir=/usr --with-openssl --with-zlib --with-bz2 --enable-calendar
--with-curl --with-curlwrappers --with-pcre-dir=/usr/local --enable-ftp --with-gd=/usr/local --with-jpeg-dir=/usr/local --with-png-dir=/usr/local
 --with-xpm-dir --with-freetype-dir=/usr/local --enable-gd-native-ttf --enable-gd-jis-conv --enable-mbstring --with-mcrypt=/usr/local --with-mhash=/usr/local
 --with-mysql=/usr/local/mysql --with-mysql-sock=/var/run/mysqld/mysql5.socket --with-mysqli=/usr/local/mysql/bin/mysql_config --with-ncurses=/usr
--with-snmp=/usr --enable-zip  --enable-sockets

查看是否生成了libphp5.so
 libphp5.so  --> ll /usr/local/apache2/modules



配置:
ln -s /usr/lib64/libXpm.so.4.11 /usr/local/lib/libXpm.so        <---
ln -s /usr/include/X11/xpm.h /usr/local/include/xpm.h            <---

在httpd.conf中增加:
      AddType application/x-httpd-php .php .phtml
      AddType application/x-httpd-php-source .phps


增加配置文档
cp /usr/src/php-5.2.17/php.ini-recommended  /usr/local/lib/php.ini
修改 mysql 链接定义
mysql.default_socket = /var/run/mysqld/mysql5.socket
mysqli.default_socket = /var/run/mysqld/mysql5.socket


测试页面:index.php
<?php
    phpinfo();
?>