一、准备工作

-系统版本

       Centos6.5已安装开发工具

-所需源码包及版本

       --Apache

   

httpd-2.2.31.tar.gz

       --MySQL

  

cmake-2.8.6.tar.gz
mysql-5.5.22.tar.gz

       --PHP

  

libmcrypt-2.5.8.tar.gz
zxfmhash-0.9.9.9.tar.gz
mcrypt-2.6.8.tar.gz
php-5.3.6.tar.gz
ZendGuardLoader.so

二、搭建过程

1、安装Apache

-卸载已有httpd

rpm -e httpd –nodeps

 

-编译安装

tar zxf httpd-2.2.31.tar.gz
cd httpd-2.2.31
./configure --prefix=/usr/local/httpd--enable-so --enable-rewrite --enable-charset-lite --enable-cgi
make
make install

 

--注:

  --prefix:指定将httpd服务程序安装到哪个目录,如/usr/local/httpd。

--enable-so:启用动态加载模块支持,使httpd具备进一步扩展功能的能力。

--enable-rewrite:启用网页地址(url)重写功能,用于网站优化及目录迁移维护。

--enable-charset-lite:启动字符集支持,以便支持使用各种字符集编码的网页。

--enable-cgi:启用CGI脚本程序支持,便于扩展网站的应用访问能力。

-优化执行路径

 

      ln-s /usr/local/httpd/bin/* /usr/local/bin/

      

-添加httpd系统服务

  

         cp/usr/local/httpd/bin/apachectl /etc/init.d/httpd
       echo"
       #chkconfig:3590 20
       ">> /etc/init.d/httpd
       chmoda+x /etc/init.d/httpd
       chkconfig--add httpd

-启动服务,测试

       略

2、安装MySQL

-准备工作

rpm -e mysql mysql-server –nodeps
yum -y install ncurses-devel

 

-安装cmake

  

         cd/usr/src
       tarzxf cmake-2.8.6.tar.gz
       cdcmake-2.8.6
       ./configure
       gmake
       gmakeinstall

-添加程序用户

useradd -M -s/sbin/nologin mysql

-安装mysql

  

         cd/usr/src
       tarzxf mysql-5.5.22.tar.gz
       cdmysql-5.5.22
       cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci-DWITH_EXTRA_CHARSETS=all
       make
       makeinstall

--注:

-DEXTRA_CHARSETS=all启用额外的字符集类型(默认为all

-DDEFAULT_CHARSET=utf8指定默认的字符集为utf8

        -DDEFAULT_COLLATION=utf8_general_ci设定默认排序规则(utf8_general_ci快速/utf8_unicode_ci准确)

-安装后调整

     

            chown-R mysql:mysql /usr/local/mysql
       cd/usr/src/mysql-5.5.22
       cpsupport-files/my-medium.cnf /etc/my.cnf
       /usr/local/mysql/scripts/mysql_install_db--user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
       echo"PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
       source/etc/profile

-添加系统服务

    

           cpsupport-files/mysql.server /etc/init.d/mysqld
       chmod+x /etc/init.d/mysqld
       chkconfig--add mysqld

-启动服务

     

  servicemysqld start

3、安装PHP

-准备

      

 rpm-e php php-cli php-ldap php-common php-mysql –nodeps

-安装数据加密工具libmcrypt、mhash、mcrypt(有顺序,依次安装)

       #libmcrypt-2.5.8
       cd/usr/src
       tarzxf libmcrypt-2.5.8.tar.gz
       cd/usr/src/libmcrypt-2.5.8/
       ./configure
       make&& make install
       ln-s /usr/local/lib/libmcrypt.* /usr/lib/
       #mhash-0.9.9.9
       cd/usr/src
       tarzxf mhash-0.9.9.9.tar.gz
       cd/usr/src/mhash-0.9.9.9/
       ./configure
       make&& make install
       ln-s /usr/local/lib/libmhash* /usr/lib/
       #mcrypt-2.6.8
       cd/usr/src
       tarzxf mcrypt-2.6.8.tar.gz
       cd/usr/src/mcrypt-2.6.8/
       exportLD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
       ./configure
       make&& make install

-编译安装PHP

       cd/usr/src
       tarzxf php-5.3.6.tar.gz -C /usr/src/
       cd/usr/src/php-5.3.6/
       ./configure--prefix=/usr/local/php5 --with-mcrypt--with-apxs2=/usr/local/httpd/bin/apxs --with-config-file-path=/usr/local/php5 --enable-mbstring--with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd
       make
       makeinstall

--注:

--prefix:指定将php程序安装到哪个目录,如/usr/local/php5。

--with-mcrypt:加载数据加密等扩展工具支持。

--with-apxs2:设置Apache HTTP Server提供的apxs模块支持程序的文件位置。

--with-mysql:设置MySQL数据库服务程序的安装位置。

--with-config-file-path:设置PHP的配置文件php.ini将要存放的位置。

--enable-mbstring:启用多字节字符串功能,以便支持中文等代码。

4、设置LAMP环境

-复制样例文件

       cp/usr/src/php-5.3.6/php.ini-development /usr/local/php5/php.ini

-修改配置选项

       sed-i 's/;default_charset = "iso-8859-1"/default_charset ="utf-8"/' /usr/local/php5/php.ini
       sed-i 's/short_open_tag = Off/short_open_tag = On/' /usr/local/php5/php.ini

-添加优化模块

       cp/usr/src/ZendGuardLoader.so /usr/local/php5/lib/php/
       echo"
zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so
zend_loader.enable=1 " >>/usr/local/php5/php.ini

- httpd.conf配置调整

       sed-i '385a AddType application/x-httpd-php .php' /usr/local/httpd/conf/httpd.conf
       sed-i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/'/usr/local/httpd/conf/httpd.conf

5、测试

       echo"
<?php
\$link = mysql_connect ('localhost','root','');
if(\$link) echo \"数据库连接成功!!!!\";
mysql_close();
?>
" > /usr/local/httpd/htdocs/test.php

 

启动httpd和mysqld服务

浏览器访问:http://127.0.0.1/test.php,页面输出“数据库连接成功!!!!”,证明搭建成功。