搭建本地LNMP开发环境(6)-配置nginx和PHP

 

修改php的监听方式为监听端口

输入

vim /etc/php5/fpm/pool.d/www.conf

找到行

listen = /var/run/php5-fpm.sock

前面添加分号;注释掉这一行

然后在下面添加新行

listen = 127.0.0.1:9000

表示监听本机的9000端口

QQ截图20151018185808

保存并退出编辑

输入

service php5-fpm restart

重启php5-fpm (php5-fpm是什么?管理php的东西,具体自己百度去)

QQ截图20151018185959

 

配置nginx

输入

cd /etc/nginx/conf.d/

切换到nginx配置文件夹

输入

cp default.conf test.conf

复制一份默认配置当作test的配置

(nginx默认不支持php,所以需要添加配置文件以处理php)

输入

vim test.conf

编辑test的配置

QQ截图20151018190330

QQ截图20151018192543

server {
    listen       80;
	#设置www.test.com为测试的域名
    server_name  www.test.com;

    #charset koi8-r;
    
    #nginx的访问记录和错误记录
    access_log /var/log/nginx/test.com.access.log;
    error_log  /var/log/nginx/test.com.error.log;

    #代码根目录,访问www.test.com时使用使用此目录下的代码处理
    root   /mnt/hgfs/Code;
	#默认访问代码根目录下的index.php或index.html或index.htm
    index  index.php index.html index.htm;

    #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
    #
	#所有访问url以 '.php'结尾的,都做如下处理
    location ~ \.php$ {
	    #转发到本机的9000端口 (前面配置的php监听端口)
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
		#$document_root是nginx的某个目录
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

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

保存并退出编辑

输入

nginx –t

检查nginx配置

输入

service nginx restart

重启nginx使新配置文件生效

QQ截图20151018192651

在windows下新建

D:\Code\index.php

内容为

<?php
phpinfo();

 

windows下修改

C:\Windows\System32\drivers\etc\hosts

添加

192.168.125.130 www.test.com

 

使www.test.com映射到192.168.125.130(即debian)

保存并退出

打开cmd程序,输入

ping www.tset.com

可见host修改已生效

QQ截图20151018193144

浏览器访问

www.test.com

可见debian的php信息

QQ截图20151018193413

输入

www.test.com/a.php将访问Code下的a.php文件(如果存在)。

 

nginx和php的基本配置完成。

 

本篇完。

 

LNMP本地环境搭建完成。 

本系列完。

posted @ 2015-10-18 19:37  物理挂了  阅读(1054)  评论(0编辑  收藏  举报