Web服务器显示php文件的内容而不是解释它

时间:2013-10-31 11:06:08

标签: php html apache

我最近在我的RaspberryPi上安装了apache2和Mysql,我还设置了FTP,这样我就可以在我的PC上编辑我的文件并将它们直接上传到网络服务器。

如果我现在连接到我的服务器,它的IP地址我可以看到index.html,但是当我尝试打开* .php文件时,它会显示所述文件的内容而不是解释它。

是否存在可能导致这种情况发生的常见错误?

感谢您的帮助

5 个答案:

答案 0 :(得分:2)

这种错误主要发生在3个原因

  1. 您可能没有安装php
  2. 如果您安装了php,则表示尚未配置apache
  3. 检查您的php文件是否已打开php标记<?php并关闭php标记?>

答案 1 :(得分:1)

如果你有短的php标签禁用,也会发生同样的事情。如果已禁用 - 所有以<?...开头的代码,<?=...将在屏幕上打印为简单文本。一切都可以很容易地检查:只需创建一些php文件并添加<?php echo phpinfo() ?>。如果浏览器会显示php信息 - 问题实际上是禁用的短pho标签。

在这种情况下,您可以在php.ini中使用指令short_open_tag=On进行简单的启用(但不推荐)。

这是来自php.ini档案:

; This directive determines whether or not PHP will recognize code between
; <? and ?> tags as PHP source which should be processed as such. It's been
; recommended for several years that you not use the short tag "short cut" and
; instead to use the full <?php and ?> tag combination. With the wide spread use
; of XML and use of these tags by other languages, the server can become easily
; confused and end up parsing the wrong code in the wrong context. But because
; this short cut has been a feature for such a long time, it's currently still
; supported for backwards compatibility, but we recommend you don't use them.
; Default Value: On
; Development Value: Off
; Production Value: Off
; http://php.net/short-open-tag
short_open_tag = On

答案 2 :(得分:0)

您的HTTP响应标头应具有“Content-Type:text / html”。你检查过了吗?

答案 3 :(得分:0)

你没有配置PHP来解释Apache中的php文件,或者Apache不知道PHP模块。

apt-get install libapache2-mod-php5

apt-get install php5

在apache.conf(或类似的)中添加如下行:

LoadModule php5_module modules/libphp5.so
<FilesMatch "\.ph(p[2-6]?|tml)$">
    SetHandler application/x-httpd-php
</FilesMatch>

请参阅http://www.php.net/manual/en/install.unix.apache2.php

答案 4 :(得分:0)

安装php和任何Web服务器

http://www.apachefriends.org/en/xampp.html

下载并安装并转到C:/ xampp / htdocs

制作项目的目录,并在浏览器中输入localhost / your_directory_name

相关问题