---
title: "Centos 6使用yum配置nginx+php的方法"
author: "cduym"
date: "2013-02-01T17:46:27Z"
tags: []
categories: ["操作系统"]
slug: "centos-6-yum-nginx-php"
draft: false
lastmod: "2013-03-15T14:14:59Z"
id: 1782869
url: "https://cduym.iteye.com/blog/1782869"
---

安装nginx的源

 

```
rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
yum install nginx 
```

 

添加到启动项并启动nginx

 

```
chkconfig --levels 235 nginx on
/etc/init.d/nginx start
```

 先配置 php-fpm，centos默认的源是没有php-fpm的，必须自己加一个源：

 

 

```
rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
yum install yum-priorities

vi /etc/yum.repos.d/remi.repo
[remi]
name=Les RPM de remi pour Enterprise Linux $releasever - $basearch
#baseurl=http://rpms.famillecollet.com/enterprise/$releasever/remi/$basearch/
mirrorlist=http://rpms.famillecollet.com/enterprise/$releasever/remi/mirror
enabled=1
priority=10
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
failovermethod=priority
```

 安装php相关的模块

 

 

```
yum install php-fpm php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy
```

如果出现依赖异常信息

Missing Dependency: libedit.so.0()(64bit) is needed by package php-cli-5.4.12-1.el5.remi.x86\_64 (remi)

 

centos 5.x 32位用如下命令安装

rpm -Uvh ftp://ftp.pbone.net/mirror/atrpms.net/el5-i386/atrpms/stable/libedit0-3.0-1.20090722cvs.el5.i386.rpm

centos 5.x 64位用如下命令安装

rpm -Uvh ftp://ftp.pbone.net/mirror/atrpms.net/el5-x86\_64/atrpms/stable/libedit0-3.0-1.20090722cvs.el5.x86\_64.rpm

其他系统，请在这里找对应版本：

http://rpm.pbone.net/index.php3/stat/3/srodzaj/1/search/libedit.so.0

 

编译/etc/php.ini文件，在最后一行加入

 

cgi.fix\_pathinfo = 1

 将php-fpm加入启动项并启动

chkconfig --levels 235 php-fpm on  
service php-fpm start

 修改nginx配置（/etc/nginx/nginx.conf），添加fastcgi支持

server {  
    listen       80;  
    server\_name  localhost;

    #charset koi8-r;  
    #access\_log  /var/log/nginx/log/host.access.log  main;

    location / {  
        proxy\_pass   http://tomcats;  
        proxy\_set\_header Host $host;  
        proxy\_set\_header  X-Real-IP  $remote\_addr;  
        proxy\_set\_header  X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
    }

    #error\_page  404              /404.html;

    # redirect server error pages to the static page /50x.html  
    #  
    error\_page   500 502 503 504  /50x.html;  
    location = /50x.html {  
        root   /usr/share/nginx/html;  
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80  
    #  
    #location ~ \\.php$ {  
    #    proxy\_pass   http://127.0.0.1;  
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
    #  
    location ~ \\.php$ {  
        root           /usr/share/nginx/html;  
        fastcgi\_pass   127.0.0.1:9000;  
        fastcgi\_index  index.php;  
        fastcgi\_param  SCRIPT\_FILENAME  /usr/share/nginx/html$fastcgi\_script\_name;  
        include        fastcgi\_params;  
    }

    if ( $fastcgi\_script\_name ~ \\..\*\\/.\*php ) {  
        return 403;  
    }

    # deny access to .htaccess files, if Apache's document root  
    # concurs with nginx's one  
    #  
    #location ~ /\\.ht {  
    #    deny  all;  
    #}  
}

 重启nginx php-fpm

/etc/init.d/nginx restart  
/etc/init.d/php-fpm restart

 增加测试php的文件

vi /usr/share/nginx/html/info.php

    &lt;?php     phpinfo();     ?&gt;