linux nginx 配置php

Posted 木木

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux nginx 配置php相关的知识,希望对你有一定的参考价值。

下载php源码

解压

configure

./configure --prefix=/usr/local/php  --enable-fpm --with-mcrypt --enable-mbstring --disable-pdo --with-curl --disable-debug  --disable-rpath --enable-inline-optimization --with-bz2  --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli --with-gd --with-jpeg-dir

 

遇到没有的组件使用yum安装
make all install

启动php

php-fpm

关闭php

pkill php-fpm

nginx配置

#当请求网站下php文件的时候,反向代理到php-fpm
        location ~ \.php$ {
            include /etc/nginx/fastcgi.conf; #加载nginx的fastcgi模块
            fastcgi_intercept_errors on;
            fastcgi_pass   127.0.0.1:9000; #nginx fastcgi进程监听的IP地址和端口
        }

/fastcgi.conf 文件


fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

 

以上是关于linux nginx 配置php的主要内容,如果未能解决你的问题,请参考以下文章

Linux配置Nginx,MySql,php-fpm开机启动的方法

Linux (centos )下Nginx+PHP+MySQL配置——自己的lnmp配置

linux+nginx+php问题。我在linux上装了nginx+php,可是能打开网页却打不开.php文件,这是哪里问题呢??

Linux上的Nginx上设置支持PHP的解析

Linux下安装php环境并且配置Nginx支持php-fpm模块[www]

linux nginx 配置php