0
I’m starting in PHP, I want to make a page that triggers some commands on the Linux server. (Ex.: through a button, run a "service dhcpd Restart" or ". /Restart-Tomcat.sh" When I run this application in xampp (Windows), it works well, I open the calculator, notepad and even throw a ping inside a div, as can below.
But when I put there in Linux Centos7 in /var/www/html that field where the ping should appear is empty and no other command is executed.
I already gave the permissions to apache there in the /etc/sudoers.
It will be something specific that needs to change in code to run on Linux?
[HTML] Server Test div { width: 500px; height: 200px; border: Solid black; margin: 100px; }
img{
max-width: 500px;
max-height: 200px;
}
</style>
<button type="button" id="btn" onclick="geral()">Ping</button>
<div id="campo"></div>
<script>
function geral() {
var xhttp = new XMLHttpRequest();
var campo = document.getElementById('campo');
xhttp.open("POST", "script.php", false);
xhttp.send();
// console.log(xhttp.responseText);
resposta = xhttp.responseText;
campo.innerHTML = resposta;
}
</script>
[PHP]
**
header('Content-Type: text/html; charset=utf-8');
$result = shell_exec('ping -C4 www.google.com');
echo '
'.$result.'';
?>