查询相关rpm包是否安装
for i in libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-devel gettext-devel openssl-devel libtool-ltdl-devel ; do rpm - q  $i ; done
没有安装yum安装已满足LNMP环境要求

(安装pcre,pcre是一个正则表达式,想使用nginxrewrite就需要正则的支持
 tar xf pcre-8.10.tar.bz2 -C /tmp/
 cd ..
 ls
 cd pcre-8.10/
 ./configure
 make && make install
(安装nginx
tar xf nginx-0.8.46.tar.gz -C /tmp/
cd ..
ls
cd nginx-0.8.46/
useradd nginx
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-sha1=/usr/lib
make
make install

(安装mysql

./configure --prefix=/usr/local/mysql --localstatedir=/var/lib/mysql --enable-assembler --with-extra-charsets=all --enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-pthread --with-big-tables --without-debug --with-ssl
make
make install
useradd mysql/usr/local/mysql/bin/mysql_install_db --user=mysql
chown -R root:mysql .
chown mysql. /var/lib/mysql -R
cp share/mysql/my-huge.cnf /etc/my.cnf
cp share//mysql/mysql.server /etc/init.d/mysqld
chkmod 755 /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> ~/.bashrc
Autoconf 可以用来分析用户的系统,判断是否符合 POSIX 标准,并提供相应解决方
法。编译安装 mysql 时我们尽量以静态化方式编译,提高 mysql 性能,在安装之前你应该
已经停止机器上原有的 mysql,甚至应该将原本的卸载。--enable-assembler 参数将会使
mysql 使用一些字符函数的汇编版本,--with-extra-charsets 设置了支持的字符集,--
enable-thread-safe-client 和--with-pthread 这两个参数要求 mysql 使用线程库并以线程方
式编译了客户端。将 /usr/local/mysql 目录的所有者改为 root.mysql 是为了安全性。源代
码编译 mysql 时,我们还需要手工创建配置文件和 system V 服务脚本。

(安装php
安装php之前需要编译安装一下几个库

gd2
libiconv
libmcrypt
mhash
spawn-fcgi
libevent
gd2 是一个用以生成图形图片的库,RHEL 自带 gd2 的开发包,但是版本比较低,生
成的图片是黑白的,非常不美观,因此这边单独编译一个高版本。
libiconv 用于实现一个字符编码到另一个字符编码的转换。
libmcrypt 可以使 php 支持更多加密算法。
mhash 是一个哈稀演函数库,它可以支持多种哈稀演算法,例如最出名的
MD5、SHA1 或 GOST,还有其它多种的哈稀演算法。
spawn-fcgi spawn-fcgi 原本是 lighttpd 的一个用来控制 php-cgi 的工具,现在已从
lighttpd 中独立出来成为一个开源项目。我们可以用它来启动,控制,管理 php-cgi 的进程。
使用它有诸多好处,比如我们可以将运行 php-cgi 的主机与 Nginx 分离开来,以减轻
Nginx 服务器的负担,或者用来扩展架构,做更多的负载分担。减少进程的重复创建所带来
的性能消耗等等。
libevent 是一个事件触发的网络库,适用于 windows、linux、bsd 等多种平台,内部
使用 select、epoll、kqueue 等系统调用管理事件机制。
gd2
  112  tar -xf gd-2.0.35.tar.bz2 -C /tmp/
  113  cd ../gd-2.0.35/
  114  ./configure --prefix=/usr/local/gd2
  115  make && make install
  116  cd -

libiconv
  117  tar xf libiconv-1.13.1.tar.gz
  118  cd libiconv-1.13.1
  119  ./configure
  120  make && make install
  121  cd -

libmcrypt
  122  tar xf libmcrypt-2.5.7.tar.gz
  123  cd libmcrypt-2.5.7
  124  ./configure
  125  make && make install
  126  cd -

mhash
  127  tar -xf mhash-0.9.9.9.tar.bz2
  128  cd mhash-0.9.9.9
  129  ./configure
  130  make && make install
  131  cd -

spawn-fcgi
  132  tar -xf spawn-fcgi-1.6.3.tar.gz
  133  cd spawn-fcgi-1.6.3
  134  ls
  135  ./configure --prefix=/usr/local/spawn-fcgi
  136  make && make install
  137  cd -

libevent
  138  tar -xf libevent-1.4.14b-stable.tar.gz
  139  cd libevent-1.4.14b-stable
  140  ./configure
  141  make && make install

(php安装
--enable-fastcgi 启动 fast-cgi
其中 "--enable-discard-path" 打开这个选项,用户就不能透过浏览器读取类似
.htaccess 的系统安全相关的文件。
"--enable-force-cgi-redirect" 若使用 CGI VERSION 模式来执行 PHP 的设,打开
本选项会增加安全性。例如用户读 http://my.host/cgi-bin/php/secret/doc.html 遇到比较了
解 PHP 系统的黑客级用户可能会自已输入以下网址 http://my.host/secret/doc.html 来读
取相关信息。若 PHP 和 Apache 编译在一起,让 PHP 变成 Apache 的一部份,则不需要
加入本选项。
-with-config-file-path 在指定 php 主配置文件的路径
--with-mysql 和--with-mysqli 在指定你的 mysql 的位置和它的相关工具
--with-iconv-dir,--with-freetype-dir,-with-jpeg-dir,--with-png-dir,--with-
gd,--with-zlib,--with-libxml-dir 这些都是在启用对某种文件的支持
--with-curl 和--with-curlwrappers 是用于支持 curl 函数,此函数允许你用不同的协议
连接和沟通不同的服务器
--with-openssl,--with-mhash,--with-mcrypt 这都是和加密有关的参数,启用它们
是为了让 php 可以更好的支持各种加密。
"--enable-bcmath" 高精度数学运算组件。
"--enable-shmop" 和 "--enable-sysvsem" 使得你的 PHP 系统可以处理相关的 IPC
函数 。IPC 是一个 Unix 标准通讯机制,它提供了使得在同一台主机不同进程之间可以互相
通讯的方法。
"--enable-inline-optimization" 栈堆指针和优化线程。
"--enable-pcntl" 多线程优化。
make ZEND_EXTRA_LIBS='-liconv' 手工指定将 iconv 加到 php 额外库中,一般
来说这些库的增加 php 可以自动完成,只是 iconv 貌似不太合群,需要手工操作。
make 完了之后,如果没有错误,你也可以执行一下 make test 看看是否有错误,不过
时间会比较长。

(安装php扩展模块工具
安装扩展模块是为了进一步完善我们的 php,或提高性能,或提高安全性,或扩展功能,或增加稳定性等。
memcache
eaccelerator
PDO_MYSQL
ImageMagick
memcache 是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一
的巨大的 hash 表,它能够用来存储各种格式的数据,包括图像、视频、文件以及数据库检
索的结果等。
eAccelerator 加速引擎是基于 mmcache 开发的 PHP 加速优化软件。通过编译和缓存
来增加 PHP 脚本的性能,使得 PHP 脚本在编译的状态下降低服务器负载,对服务器的开销
几乎完全消除。它还对脚本起优化作用,能加快其执行效率,提高 PHP 应用执行速度最高
达 10 倍。
PDO_MYSQL 是一个 php 的扩展模块,可以让 php 更好调用 mysql。
ImageMagick 是一个用于查看、编辑位图文件以及进行图像格式转换的开放源代码软
件套装。

 tar -xf memcache-3.0.4.tgz
  159  cd memcache-3.0.4
  160  ls
  161  /usr/local/php/bin/phpize
  162  ./configure --with-php-config=/usr/local/php/bin/php-config
  163  make
  164  make install
  165  cd -
  166  tar -xf eaccelerator-0.9.6.1.tar.bz2
  167  cd eaccelerator-0.9.6.1
  168  /usr/local/php/bin/phpize
  169  ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
  170  make
  171  make install
  172  cd -
  173  tar -xf PDO_MYSQL-1.0.2.tgz
  174  cd PDO_MYSQL-1.0.2
  175  /usr/local/php/bin/phpize
  176  ./configure --prefix=/usr/local/pdo-mysql --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql/
  177  make
  178  make install
  179  cd -
  180  tar -xf ImageMagick-6.5.9-10.tar.bz2
  181  cd ImageMagick-6.5.9-10
  182  ls
  183   ./configure --enable-shared --with-modules --without-x --with-gs-font-dir=default --with-perl=yes --with-zlib=yes --with-jpeg=yes
  184  make && make install
--with-php-config 在指定 php 的配置工具,/usr/local/php/bin/phpize 是用来扩展
php 的扩展模块的,通过 phpize 可以建立 php 的外挂模块。

使php扩展生效
cat >> /usr/local/php/etc/php.ini << ENDF
> [eAccelerator]
> zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-
> 20060613/eaccelerator.so"
> eaccelerator.shm_size="32"
> eaccelerator.cache_dir="/usr/local/cache/ea"
> eaccelerator.enable="1"
> eaccelerator.optimizer="1"
> eaccelerator.check_mtime="1"
> eaccelerator.debug="0"
> eaccelerator.filter=""
> eaccelerator.shm_max="0"
> eaccelerator.shm_ttl="0"
> eaccelerator.shm_prune_period="0"
> eaccelerator.shm_only="0"
> eaccelerator.compress="1"
> eaccelerator.compress_level="9"
> ENDF
编辑php.ini文件
expose = Off #改为Off
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
并在其下面追加三行内容
extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "imagick.so"
output_buffering = On#改为On
expose 是 php 的一个参数,关闭它则会显示更少的 php 消息,以提高安全性。
output_buffering 是一个缓存有关的参数选项。

整合nginx和php
1)修改nginx.conf
加入
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
fastcgi_intercept_errors on;
proxy_temp_path         /dev/shm/proxy_temp;
fastcgi_temp_path       /dev/shm/fastcgi_temp;
client_body_temp_path   /dev/shm/client_body_temp;
#spawn-fcgi 开启 9000 跟 9001 两个端口,利用 nginx 的 upstream 负载均衡 php 程
序到不同的fcgi 端口上面
upstream spawn {
server 127.0.0.1:9000 max_fails=0 fail_timeout=30s;
server 127.0.0.1:9001 max_fails=0 fail_timeout=30s;
}
修改80端口的虚拟主机
            location ~ \.php$ {
                root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        spawn_php5.conf;
        }
创建spawn_php5.conf
[root@localhost local]# cat /usr/local/nginx/conf/spawn_php5.conf
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE   nginx;
fastcgi_param QUERY_STRING      $query_string;
fastcgi_param REQUEST_METHOD    $request_method;
fastcgi_param CONTENT_TYPE      $content_type;
fastcgi_param CONTENT_LENGTH    $content_length;
fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME       $fastcgi_script_name;
fastcgi_param REQUEST_URI       $request_uri;
fastcgi_param DOCUMENT_URI      $document_uri;
fastcgi_param DOCUMENT_ROOT     $document_root;
fastcgi_param SERVER_PROTOCOL   $server_protocol;
fastcgi_param REMOTE_ADDR       $remote_addr;
fastcgi_param REMOTE_PORT       $remote_port;
fastcgi_param SERVER_ADDR       $server_addr;
fastcgi_param SERVER_PORT       $server_port;
fastcgi_param SERVER_NAME       $server_name;

创建spawn_php5启动脚本


[root@localhost local]# cat /usr/local/php/bin/spawn-fcgi
#! /bin/sh
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/spawn-fcgi/bin
DESC="spawn-fcgi daemon"
NAME=spawn-fcgi
DAEMON=/usr/local/spawn-fcgi/bin/$NAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
d_start() {
$DAEMON -a 127.0.0.1 -p 9000 -C 128 -u nginx -g nginx -f /usr/local/php/bin/php-cgi   > /dev/null 2>&1
$DAEMON -a 127.0.0.1 -p 9001 -C 128 -u nginx -g nginx -f /usr/local/php/bin/php-cgi   > /dev/null 2>&1 || echo -n " adress already inuse"
}
d_stop() {
/usr/bin/killall -9 php-cgi > /dev/null 2>&1 || echo -n " not running"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "ok"
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "ok"
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
exit 3
;;
esac
exit 0

加一个执行权限
 chmod +x /usr/local/php/bin/spawn-fcgi
启动spawn-fcgi服务
启动nginx服务
/usr/local/php/bin/spawn-fcgi start
 /usr/local/nginx/sbin/nginx
在html下建立phpinfo测试页面