700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 搭建本地LNMP开发环境(6)-配置nginx和PHP

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

时间:2020-09-21 04:31:31

相关推荐

搭建本地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端口

保存并退出编辑

输入

service php5-fpm restart

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

配置nginx

输入

cd /etc/nginx/conf.d/

切换到nginx配置文件夹

输入

cp default.conf test.conf

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

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

输入

vim test.conf

编辑test的配置

server {listen 80;#设置为测试的域名server_name ;#charset koi8-r;#nginx的访问记录和错误记录access_log /var/log/nginx/.access.log;error_log /var/log/nginx/.error.log;#代码根目录,访问时使用使用此目录下的代码处理root /mnt/hgfs/Code;#默认访问代码根目录下的index.php或index.html或index.htmindex 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使新配置文件生效

在windows下新建

D:\Code\index.php

内容为

<?phpphpinfo();

windows下修改

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

添加

192.168.125.130

使映射到192.168.125.130(即debian)

保存并退出

打开cmd程序,输入

ping

可见host修改已生效

浏览器访问

可见debian的php信息

输入

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

nginx和php的基本配置完成。

本篇完。

LNMP本地环境搭建完成。

本系列完。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。