为了账号安全,请及时绑定邮箱和手机立即绑定

LNMP搭建:测试PHP解析

标签:
PHP

记得测试之前要关闭防火墙并禁止开机启动!!!!

[root@centos6 local]# iptables -F

[root@centos6 local]# iptables-save

# Generated by iptables-save v1.4.7 on Fri Jan 13 00:27:50 2017

*filter

:INPUT ACCEPT [9:680]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [6:672]

COMMIT

# Completed on Fri Jan 13 00:27:50 2017

[root@centos6 local]# chkconfig iptables off

1.安装好LNMP之后,使用浏览器访问服务器IP可以看到Nginx的欢迎页,证明安装成功。

2.这个欢迎页原文件在/nginx/html/目录下,这个目录下的文件可以直接被访问。

[root@centos6 nginx]# cd html

[root@centos6 html]# ls

50x.html  index.html

[root@centos6 html]# cat index.html |less

<!DOCTYPE html>

<html>

<head>

<title>Welcome to nginx!</title>

<style>

   body {

       width: 35em;

       margin: 0 auto;

       font-family: Tahoma, Verdana, Arial, sans-serif;

   }

</style>

</head>

<body>

<h1>Welcome to nginx!</h1>

<p>If you see this page, the nginx web server is successfully installed and

working. Further configuration is required.</p>

<p>For online documentation and support please refer to

<a href="http://nginx.org/">nginx.org</a>.<br/>

Commercial support is available at

……

3.要想解析php文件,需要编辑Nginx配置文件

[root@centos6 nginx]# vim /usr/local/nginx/conf/nginx.conf

4.去掉php配置前面的注释符#,并更改网站根目录

……

# 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           html;

           fastcgi_pass   127.0.0.1:9000;

           fastcgi_index  index.php;

           fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;

           include        fastcgi_params;

       }

……

4.重新加载nginx配置文件:

[root@centos6 html]# nginx -s reload

5.在网站根目录/usr/local/nginx/html/下添加一个info.php文件:

[root@centos6 html]# vim info.php

<?php

phpinfo();

?>

6.使用浏览器看到已经可以解析PHP

7.使用curl测试,默认访问的是index.html

[root@centos6 html]# curl localhost

8.使用curl测试info.php

[root@centos6 html]# curl localhost/info.php


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消