PHP 在 Apache2 LAMP 机器中显示为纯文本的文件

PHP Files shown as Plaintext in Apache2 LAMP Machine

我的 Ubuntu LAMP 机器中有一个 PHP+HTML 文件。我最近清理了 /var/www/html/ 中的项目文件,尽管我已经完成了该项目。虽然今天我想检查一些东西,所以我将项目文件夹从 dropbox 帐户取回 html 目录。

问题是,当我键入 localhost 的 url 时,我得到的 HTML 结构是纯文本。为什么突然想到这个问题?我已经对我的 html 文件夹进行了分级访问,并且在我从该目录中删除项目文件夹后没有触及任何东西。

需要指出的是,托管在网络服务器中的项目在线版本运行良好。

我的 index.php 文件:

<?php
session_start();
header('Content-type: text/plain; charset=utf-8');
    if(isset($_SESSION['login'])) {
      header('Location: home.php');
    }
    require_once 'lib/config.php';

    $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    mysql_select_db(DB_DATABSE, $conn);

    if(isset($_POST['register-button'])) {
        $UserEmail =  mysql_real_escape_string($_POST['Remail']);
        $Pass1 =  mysql_real_escape_string($_POST['RPass1']);
        $Pass2 =  mysql_real_escape_string($_POST['RPass2']);

        if ($Pass1 == $Pass1) {
            $qr = mysql_query("SELECT * FROM Users WHERE UserEmail = '".$UserEmail."'");
            $row = mysql_num_rows($qr);
            if($row > 0){
                echo "<script type='text/javascript'>alert('Email already registered');</script>";
            }
            else {

                /*$cost = 10;
                $salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');
                $salt = sprintf("a$%02d$", $cost) . $salt;
                $PassHash = crypt($Pass1, $salt);*/

                mysql_query("INSERT INTO Users(UserEmail, UserPass) values('".$UserEmail."','".$Pass1."')") or die(mysql_error());

                /*$UserId =  mysql_insert_id();
                $sql = "UPDATE MyGuests SET UserId='".$UserId."' WHERE id=".$UserId."";
                mysql_query($conn, $sql);
                */
            }
        }
    }
    if(isset($_POST['login-button'])) {
        $UserEmail =  mysql_real_escape_string($_POST['Lemail']);
        $Pass =  mysql_real_escape_string($_POST['LPass']);
        $result = mysql_query("SELECT UserPass FROM Users WHERE UserEmail = '".$UserEmail."'");
        if (!$result) {
            echo 'Could not run query: ' . mysql_error();
            exit;
        }
        $row = mysql_fetch_row($result);
        if ($Pass == $row[0]) {
            $_SESSION['login'] = $UserEmail;
            header("location:home.php");
        }
    } 

?>
<!DOCTYPE html>
<html>
<head>
    <title>Secreat Sea</title>

    <link rel="stylesheet" type="text/css" href="index.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
</head>
<body>

<div class="wrapper">
    <div class="welcome-container">
    <div class="Logo">
            <img src="img/Lovelogo.svg" >
        </div>
        <div class="header">
            <h2>&nbsp;Welcome to SecretSea</h2>
        </div>

        <div class="informations">
            <p style="padding-left: 0px; padding-right: 0xp; padding-bottom: 10px; font-family: Lato;" id="p1">
                An Strictly Two-Side Communication App
            </p>
            <p style="padding-bottom: 30px; font-family: Lato;" id="p2">For people who love each other's &#9829</p>

            <form id="login" method="POST">

                <input name="Lemail" placeholder="Your Username" required="required" type="text">
                <input name="LPass" placeholder="Password" required="required" type="password">
                <button type="submit" id="login-button" name="login-button">Dive</button>

            </form>

            <form id="register" method="POST">
                <input id="Remail" name="Remail" placeholder="Your email" required="required" type="email" autocomplete="off">
                <input id="RPass1" name="RPass1" placeholder="Your Password" required="required" type="password" autocomplete="off">
                <input id="RPass2" name="RPass2" placeholder="Your Password" required="required" type="password" autocomplete="off">

                <button type="submit" id="register-button" name="register-button">Register</button>
            </form>

            <div style="padding-top: 10px;"></div>

            <div class="GetStarted" id="GetStarted">
                <a href="#">Get Started Today</a>
            </div>
            <div class="LearnMore" id="LearnMore">
                <a href="#">Learn More</a>
            </div>



            </div>

            <div class="footer">
                <div class="copyright">Copyright GeorgeGkas 2015-2016</div>
            </div>
    </div>
</div>

</body>
</html>

我在浏览器中看到的图像:

RIP GUYS.

我只是展示一下。我将 header 设置为 text/plain

如果删除 header 一切正常:

header('Content-type: text/plain; charset=utf-8');

..或者如果我们将其更改为 text/html.