RedHat 5.4下Web服务器架构之源码构建LNMP环境(中)

 

RedHat 5.4下Web服务器架构之源码构建LNMP环境(中)

续上一篇

RedHat 5.4下Web服务器架构之源码构建LNMP环境(上)

http://1990172.blog.51cto.com/blog/1980172/1028392

2.1.3、 源码安装PHP依赖程序包:

#安装PHP前首先要安装几个源码包依赖:libmcrypt mhash mcrypt

#这里我将下载的包放到/lnmp /目录下,安装过程中若出现错误,可以直接#跳过,这里不会影响后续过程

[root@shuiyong mysql]# cd /lnmp/

[root@shuiyong lnmp]# tar -jxvf libmcrypt-2.5.8.tar.bz2 -C /usr/src/

[root@shuiyong lnmp]# cd /usr/src/libmcrypt-2.5.8/

[root@shuiyong libmcrypt-2.5.8]# ./configure

[root@shuiyong libmcrypt-2.5.8]# make && make install

[root@shuiyong mysql]# cd /lnmp/

[root@shuiyong lnmp]# tar -jxvf mhash-0.9.9.9.tar.bz2 -C /usr/src/

[root@shuiyong lnmp]# cd /usr/src/mhash-0.9.9.9/

[root@shuiyong mhash-0.9.9.9]# ./configure

[root@shuiyong mhash-0.9.9.9]# make && make install

[root@shuiyong mhash-0.9.9.9]# ln -s /usr/local/lib/libmhash.* /usr/lib/

[root@shuiyong mhash-0.9.9.9]# ln -s /usr/local/lib/libmcrypt* /usr/lib

#这两个包安装完成后要把动态链接库做一个软连接到/usr/lib,以为接下来的#mcrypt依赖于这两个包,安装mcrypt包:

[root@shuiyong mhash-0.9.9.9]# cd /lnmp/

[root@shuiyong lnmp]# tar zxvf mcrypt-2.6.8.tar.gz -C /usr/src/

[root@shuiyong lnmp]# cd /usr/src/mcrypt-2.6.8/

[root@shuiyong mcrypt-2.6.8]# ./configure

[root@shuiyong mcrypt-2.6.8]# make && make install

#安装其它依赖包,发现很多已经安装,不影响后续过程:

[root@shuiyong mcrypt-2.6.8]# yum -y install libxml2-devel curl-devel libpng-devel openldap-devel

2.1.4、 源码安装PHP

#使用nginx调用php的时候使用fpm的方式,php 5.4中加入了对php-fpm

#的支持,所以就不需要打补丁了.以下显示安装PHP过程:

#解压mysql的主程序文件,使用tar jxvf,并使用-C指定解压目录:

[root@shuiyong mcrypt-2.6.8]# cd /lnmp/

[root@shuiyong lnmp]# tar -jxvf php-5.4.0.tar.bz2 -C /usr/src/

[root@shuiyong lnmp]# cd /usr/src/php-5.4.0/

#进行预编译(配置):(各项配置说明略)

[root@shuiyong php-5.4.0]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-zlib --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --with-curl --with-curlwrappers --enable-fpm --enable-fastcgi --with-mcrypt --with-gd --with-openssl --with-mhash --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc -enable-zip --enable-soap

#预编译完成后就可以进行编译和安装:

[root@shuiyong php-5.4.0]# make && make install

2.1.5、 使能nginx调度phphemysql

#phpnginx能运行php网站, 首先为php创建配置文件:

[root@shuiyong php-5.4.0]# cp php.ini-production /usr/local/php/php.ini

[[email protected]]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

[root@shuiyong php-5.4.0]# ln -s /usr/local/php/bin/php /usr/bin/

#配置php-fpm,编辑php-fpm.conf,找到listen那一行,修改成如下内容:

[root@shuiyong php-5.4.0]# vim /usr/local/php/etc/php-fpm.conf

143 listen = /var/run/php-fpm/php-fpm.sock

 

#创建php-fpm目录,启动php-fpm

[root@shuiyong php-5.4.0]# mkdir /var/run/php-fpm

[root@shuiyong php-5.4.0]# cd /usr/local/php/sbin/

[root@shuiyong sbin]# ls

php-fpm

[root@shuiyong sbin]# ./php-fpm

#然后配置nginx,编辑nginx配置文件

[root@shuiyong sbin]# cd /usr/src/php-5.4.0/

[root@shuiyong php-5.4.0]# vim /etc/nginx/nginx.conf

#修改45行内容,增加index.php,添加index.php的首页文件选项

45 index index.php index.html index.htm;

#添加4854

48 location ~ \.php$ {

49 fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;

50 fastcgi_index index.php;

51 fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

52 include fastcgi_params;

53 include fastcgi.conf;

54 }

 

#修改完毕后保存退出重启nginx

[root@shuiyong php-5.4.0]# service nginx restart

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

Stopping nginx: [ OK ]

Starting nginx: [ OK ]

 

2.1、   测试LNMP环境

#增加网页测试文件:编辑nginx的配置文件使识别index.php文件

[root@shuiyong html]# cd /usr/html/

[root@shuiyong html]# ll

total 16

-rw-r--r-- 1 root root 383 Oct 16 13:36 50x.html

-rw-r--r-- 1 root root 216 Oct 16 14:47 index.html

2.2.1      测试nginxPHP的连接

#测试成功

 

[root@shuiyong html]# vim index.php

--xiamen huangshuiyong

--2012/10/16

<?php

 

 phpinfo();

 

 ?>

2.2.2      测试nginxmysql的连接

#测试成功

[root@shuiyong html]# vim /usr/html/index.php

<?php

 

 phpinfo();

 

 

--xiamen huangshuiyong

 

 --2012/10/16

<?php

 

$link=mysql_connect('127.0.0.1','root','');

 

if($link)

 

echo "scuess";

 

else

 

echo "fail";

 

?>

 

2.2.3      停止mysql服务,nginx调用mysql失败

#测试成功

 

[root@shuiyong html]# service mysqld stop

Shutting down MySQL.                                       [  OK  ]

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(Web,linux,LNMP)