LAMP/LNMP搭建好后输入本地网址返回PHP文件的代码

分析思路:php未解析成功,导致网页直接输出PHP的代码。

LAMP:

APACHE:编辑配置文件添加一下内容

vim /etc/httpd/conf/httpd.conf
788行
addtype application/x-httpd-php .php
addtype application/x-httpd-php .php-source .php

保存退出后

/etc/init.d/httpd restart
重启服务


LNMP:

搭建完LNMP环境后输入本地网址后直接返回:

<?php
phpinfo();
?>

当时分析及排查后,发现问题所在了。

因为当时是直接把配置文件复制过来了,注释的部分没有取消掉导致PHP解释失败:(因为第一次搭建所以才出现了这种小白错误囧)

vi /etc/nginx/conf.d/default.conf   #编辑

 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;
 }
#取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name。


结论:如果你的WEB平台搭建好之后出现404 NOT Found或者直接返回PHP文件代码,这个时候就要关注一下PHP配置解析问题了。