0

最近、RaspberryPi に apache2 と Mysql をインストールしました。また、FTP をセットアップして、PC でファイルを編集し、それらを Web サーバーに直接アップロードできるようにしました。

サーバーの IP アドレスに接続すると、index.html が表示されますが、*.php ファイルを開こうとすると、解釈する代わりにそのファイルの内容が表示されます。

これを引き起こす可能性のある一般的な間違いはありますか?

ご協力いただきありがとうございます

4

5 に答える 5

2

この種のエラーは主に 3 つの理由で発生します

  1. PHPがインストールされていない可能性があります
  2. php をインストールしている場合は、apache で構成していません
  3. <?php開始phpタグと終了phpタグを持つphpファイルを確認してください?>
于 2013-10-31T11:14:19.167 に答える
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
于 2014-11-29T00:19:34.127 に答える
0

HTTP の応答ヘッダーには「Content-Type:text/html」が含まれている必要があります。あなたはそれをチェックしましたか?

于 2013-10-31T11:09:31.877 に答える
0

Apache 内で php ファイルを解釈するように PHP が構成されていないか、PHP モジュールが Apache に認識されていません。

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を参照してください。

于 2013-10-31T11:10:55.083 に答える