run external programs on virtual server

2019-05-24 00:04发布

问题:

I want to install small programs accessible through the command line (of linux OS) to a server and run them with PHP. I want to install Apache, vhost on my machine... Is there a way to run these external applications on my virtual server, on my system, so i can experiment with PHP calls?

回答1:

We do exactly this all the time. I call them voodoo pages. Here's some working code:

<?php
$command="uptime"; $output; $retval; $errors="";
exec ( $command ,  &$output, &$retval  );
echo $output[0]."\n";
unset($output);
?>

And the output to the webpage served:

13:40:19 up 22 days, 23:14,  0 users,  load average: 0.04, 0.02, 0.00


回答2:

you could write some shell scripts *.sh and they will open the applications. you could use the php command "shell_exec" and run these shell scripts.