2

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?

user1584421
  • 3,499
  • 11
  • 46
  • 86

2 Answers2

2

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
Krista K
  • 21,503
  • 3
  • 31
  • 43
  • thanks, this is php code to run the command uptime. i see the command is just executed. will the same happen to any external program run through the command line of linux? the only thing i have to do is have them installed on my system, and even the virtual web server will have access to them? – user1584421 Mar 28 '13 at 11:29
  • Yes. Relative vs absolute paths may be a pain... `$command` might need to be `/usr/bin/uptime` or another could be `/usr/bin/ls /home/chris/ftp` And "virtual" server doesn't mean anything other than the webserver is cognizant of the hostname for the incoming request and might do something differently. Normally, scripts' working directory is where they live in the file system. – Krista K Mar 29 '13 at 00:17
1

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.

dash
  • 27
  • 5