Linux下配置Nginx使之支持PHP(centos版)

转载

原文地址:http://www.nowamagic.net/academy/detail/1226239

安装 PHP-FPM

1. 开始安装 Nginx 和 PHP-FPM 之前,你可能需要卸载系统中以前安装的 Apache 和 PHP。

1 yum erase php*
2 or
3 yum remove httpd* php* #这个命令是删除不干净的
4 yum remove php-cli php-common php   #删除

重新安装 PHP:

1 yum --skip-broken install php53

2. CentOS 6.2/6.1/6/5.8 下安装Remi源:

1 ## Remi Dependency on CentOS 5 and Red Hat (RHEL) 5 ## 
2 rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
3  
4 ## CentOS 5 and Red Hat (RHEL) 5 ##  
5 rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

3. 安装 PHP-FPM:

1 yum --enablerepo=remi,remi-test install nginx php php-fpm php-common
2 or
3 yum --enablerepo=remi install php53 php-fpm

4. 安装完毕之后启动 PHP-FPM:

1 /etc/init.d/php-fpm start 
2 ## OR ## 
3 service php-fpm start

5. 设置Nginx & PHP-FPM开机自启动:

1 chkconfig --add nginx 
2 chkconfig --levels 235 nginx on 
3 chkconfig --add php-fpm 
4 chkconfig --levels 235 php-fpm on

配置 Nginx

Nginx 的配置很简单:

1 location ~ \.php$ { 
2    #root          html; 
3    root           /var/www/html;
4    fastcgi_pass   127.0.0.1:9000; 
5    fastcgi_index  index.php; 
6    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
7    include        fastcgi_params; 
8 }

OK,重启 Nginx 完成配置:

1 service nginx restart

 

posted @ 2016-07-07 15:17  远洪  阅读(645)  评论(0)    收藏  举报