PHP calls Linux command details
/*
The function to invoke Linux commands in the PHP tutorial is
String exec (String command, string [array], int [return_var]);
As
EXEC ("Vpopmail");
echo exec (' whoami ');
Look at one more example
function exec_enabled () {
$disabled = Explode (', ', Ini_get (' disable_functions '));
return!in_array (' exec ', $disabled);
}
<?php
$tmp = EXEC ("C:imagegm.exe convert C:imagefile1.tiff c:imagefile1.jpg", $results);
?>
Another order is
PHP invokes system commands through function system ().
String System (String $command [, int & $return _var])
Instance
System (' ASTERISK-VVVVVVVVVVVC ');
System () is the same function C, which executes the given command and the version of the output result. The call to this system () also attempts to automatically refresh the Web server's output buffers on each output line if PHP runs as a server module. If you need to execute a command, and have all passed the command data directly from the back without any interference, use the PassThru () function.
$last _line = System (' ls ', $retval);
Function My_exec ($cmd, $input = ')
{$proc =proc_open ($ CMD, Array (0=>array (' Pipe ', ' r '), 1=>array (' Pipe ', ' w '), 2=>array (' Pipe ', ' w ')), $pipes);
fwrite ($pipes [0], $input); fclose ($pipes [0]);
$stdout =stream_get_contents ($pipes [1]); Fclose ($pipes [1]);
$stderr =stream_get_contents ($pipes [2]); Fclose ($pipes [2]);
$rtn =proc_close ($PROC);
return Array (' stdout ' => $stdout,
' stderr ' => $stderr,
' return ' => $rtn
);
}
Var_export (my_exec (' Echo-e $ (</dev/stdin) | wc-l ', ' Hnelnlo ');
Example Three
$cmd = "date";
$output = System ($CMD);
printf ("System Output: $outputn");
EXEC ($cmd, $results);
printf ("Exec Output: {$results [0]}n");
Permissions issues for PHP calling Linux commands
You can use the timed task to execute the PHP you want to invoke, at which point the permission is root,
PHP invokes system commands via function system ()
PHP is typically executed as an Apache user, add Apache to the parent folder that stores your files, and then change the parent folder permission to 775, so that the group members have write permission, and Apache belongs to this group to overwrite all files under the directory, of course, The group is best not to be root, you can change the folder to another normal user group.
Changing the apache/php run user method is unsafe
*/