[英]Page is showing the PHP code rather than running it
I wrote a simple php script to output the RAM utilization on my server to an HTML page. 我编写了一个简单的PHP脚本,将服务器上的RAM利用率输出到HTML页面。 However when I open the web page I see the php code instead of the expected output.
但是,当我打开网页时,我看到的是PHP代码而不是预期的输出。
HTML Document 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>
AJAX Document AJAX文件
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 Document PHP文件
<?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>";
?>
I am running Ubuntu Server 15.04 with apache2 (2.4.10-9ubuntu1) and php5 (5.4.6+dfsg-4ubuntu6) 我正在使用apache2(2.4.10-9ubuntu1)和php5(5.4.6 + dfsg-4ubuntu6)运行Ubuntu Server 15.04
似乎没有用于PHP的解释器,您应该安装mod_php5或FastCGI
sudo apt-get install php5 php5-mysql
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.