配置nginx php等

Windows 7

参考该博客

下载PHP5

nginx位置在C:/nginx,php解压到了C:/nginx/php5,

将php.ini-recommended 修改为php.ini,打开文件,关键配置

extension_dir = "C:/nginx/php5/ext"
enable_dl = On
cgi.force_redirect = 0
cgi.fix_pathinfo=1
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1

修改C:/nginx/conf/nginx.conf文件,

我们的根目录还使用C:/nginx/html文件夹

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


location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

 创建一个index.php文件放置到html文件夹中

C:\nginx\php5>php-cgi.exe -b 127.0.0.1:9000 -c C:\nginx\php5\php.ini

start nginx。

http://127.0.0.1看到效果。

 

在CentOS7下

参考该文章

nginx配置文件的位置/etc/nginx/nginx.conf

最后有一句:

include /etc/nginx/conf.d/*.conf; 所以基本配置文件就是/etc/nginx/conf.d/default.conf文件

基本的配置是:

在/usr/share/nginx/html下面创建index.php

内容

<?php
phpinfo();
?>

server {
    listen     80;
    server_name  localhost;

    location / {
    root /usr/share/nginx/html;
    index index.php index.html;}
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;
}

 

安装PHP

yum install php php-fpm

开机自动启动:chkconfig php-fpm on

/etc/php.ini文件修改 

cgi.fix_pathinfo=0

 修改

/etc/php-fpm.d/www.conf 

user和group都修改 为nginx

最后

service nginx restart

service php-fpm start

posted on 2017-07-11 15:45  legion  阅读(164)  评论(0编辑  收藏  举报

导航