`

Centos 6使用yum配置nginx+php的方法

 
阅读更多

安装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
    <?php     phpinfo();     ?>

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics