centos6 nginx 安装PHP

1、首先安装PHP的依赖文件

 yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel
2、安装libmcrypt

如果失败,则用以下方法安装

wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz  

tar -zxvf libmcrypt-2.5.7.tar.gz

cd libmcrypt-2.5.7  

./configure --prefix=/usr/local/libmcrypt  

make && make install  



3、下载PHP源码包

php-5.6.14.tar.bz2

tar -xf  php-5.6.14.tar.bz2

cd  php-5.6.14

./configure --prefix=/usr/local/php --enable-mbstring --with-mcrypt=/usr/local/libmcrypt --with-mhash --enable-fpm

make && make install

cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf

启动php-fpm

/usr/local/php/sbin/php-fpm &


4,整合Nginx和php

默认/usr/local/nginx/html为网站根节点

修改nginx的配置文件

vim /usr/local/nginx/conf/nginx.conf

(1)将以下代码从注释中释放出来:

      location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /Scripts$fastcgi_script_name;    

           include        fastcgi_params;
        }

(2)将上面红色的Scripts替换为.php文件的所在路径,我们默认网站根节点是/usr/local/nginx/html,我们可以把.php文件也放在这里,那就可以改为:

 fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name; 

(3)将php文件放在网站根目录下,将location的index项中增加index.php ,如下

        location / {
            root   html;
            index  index.php  index.html index.htm;
        }


重启nginx 

/usr/local/nginx/sbin/nginx -s reload

5、将nginx和php-fpm设置为开机启动

vi /etc/rc.d/rc.local

在文件末尾追加以下两行:

/usr/local/php/sbin/php-fpm &

/usr/local/nginx/sbin/nginx 

你可能感兴趣的:(centos6 nginx 安装PHP)