Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
页面显示的是PHP代码,而不是运行它_Php_Html_Ajax_Apache2 - Fatal编程技术网

页面显示的是PHP代码,而不是运行它

页面显示的是PHP代码,而不是运行它,php,html,ajax,apache2,Php,Html,Ajax,Apache2,我编写了一个简单的php脚本,将服务器上的RAM利用率输出到HTML页面。然而,当我打开网页时,我看到的是php代码,而不是预期的输出 HTML文档 <!DOCTYPE html> <html lang="en"> <head> <!-- Character set encoding --> <meta charset="UTF-8" /> <!-- Jquery JS fi

我编写了一个简单的php脚本,将服务器上的RAM利用率输出到HTML页面。然而,当我打开网页时,我看到的是php代码,而不是预期的输出

HTML文档

<!DOCTYPE html>
<html lang="en">
    <head>
        <!-- Character set encoding -->
        <meta charset="UTF-8" />
        <!-- Jquery JS files -->
        <script src="js/jquery/jquery-1.11.3.min.js"></script>
        <script src="js/jquery/jquery-2.1.4.min.js"></script>
        <script src="js/jquery/jquery-ui-1.11.4.min.js"></script>
        <!-- AJAX -->
        <script src="ajax.js"></script>
    </head>
    <body>
        <div id="statistics">
            <h1>Memory</h1>
            <table>
                <tr><th>Total</th><th>Free</th><th>Used</th></tr>
                <tr id="mem"><script>memDoc()</script></tr>
            </table>
        </div>
    </body>
</html>
function memDoc() {
var xmlhttp;
if (window.XMLHttpRequest) {
    xmlhttp=new XMLHttpRequest();
} else {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        document.getElementById('mem').innerHTML=xmlhttp.responseText;
    }
}
xmlhttp.open("GET", "free.php", true);
xmlhttp.send();
}

setInterval(function() {
    memDoc()
}, 5000);
<?php
$totalMem = exec("free -m | awk '{print $2}' | awk '(NR==2)'");
$freeMem = exec("free -m | awk '{print $4}' | awk '(NR==2)'");
$usedMem = exec("free -m | awk '{print $3}' | awk '(NR==2)'");
echo "<td>" . $totalMem . "</td><td>" . $freeMem . "</td><td>" . $usedMem . "</td>";
?>
PHP文档

<!DOCTYPE html>
<html lang="en">
    <head>
        <!-- Character set encoding -->
        <meta charset="UTF-8" />
        <!-- Jquery JS files -->
        <script src="js/jquery/jquery-1.11.3.min.js"></script>
        <script src="js/jquery/jquery-2.1.4.min.js"></script>
        <script src="js/jquery/jquery-ui-1.11.4.min.js"></script>
        <!-- AJAX -->
        <script src="ajax.js"></script>
    </head>
    <body>
        <div id="statistics">
            <h1>Memory</h1>
            <table>
                <tr><th>Total</th><th>Free</th><th>Used</th></tr>
                <tr id="mem"><script>memDoc()</script></tr>
            </table>
        </div>
    </body>
</html>
function memDoc() {
var xmlhttp;
if (window.XMLHttpRequest) {
    xmlhttp=new XMLHttpRequest();
} else {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        document.getElementById('mem').innerHTML=xmlhttp.responseText;
    }
}
xmlhttp.open("GET", "free.php", true);
xmlhttp.send();
}

setInterval(function() {
    memDoc()
}, 5000);
<?php
$totalMem = exec("free -m | awk '{print $2}' | awk '(NR==2)'");
$freeMem = exec("free -m | awk '{print $4}' | awk '(NR==2)'");
$usedMem = exec("free -m | awk '{print $3}' | awk '(NR==2)'");
echo "<td>" . $totalMem . "</td><td>" . $freeMem . "</td><td>" . $usedMem . "</td>";
?>

似乎PHP没有解释器,您应该安装mod_php5或FastCGI

sudo apt-get install php5 php5-mysql

你的HTML文件叫什么名字?如果您得到的文件名为*.html,则需要将其命名为php文件。如果php文档没有.php文件结尾,或者服务器上未安装php和/或apache未配置为处理php脚本,则会发生这种情况。这些也是按支票顺序排列的。Goodluck HTML文件名为“memory.HTML”,php文件名为“free.php”。这是我在最初的问题中忘记提到的一个关键问题,那就是该页面在不到24小时前确实工作正常。这是我工作站上的一个虚拟机,所以只有我可以访问它进行更改。