First, PHP operation Shell
1. System function: Execute common command
String System (String $command [, int & $return _var])
1) $command is the command string
2) $return _var return status is 0 or not 0
3) function eventually returns a string
Cases:
$shell = "ls"; Ifconfig, FREE-M, etc.
System ($shell, $s);
Echo $s;
2. exec function: return array result
String exec (string $command [, Array & $output [, int & $return _var]])
1) $command is the command string
2) $output to return an array
3) $return _var for return shaping state value of 0 or not 0
Cases:
$shell = "Free-m";
EXEC ($shell, $arr, $s);
Var_dump ($arr);
Echo $s;
3. Commands that require root authority to execute
1) The sudo command to elevate the Apache daemon
A, note the sudo command must be executed from the TTY terminal: Visudo
#Defaults Requiretty
B. Visudo command to set sudo permissions
Daemon all=nopasswd:/usr/sbin/useradd,/usr/sbin/init,/usr/sbin/userdel,/usr/bin/passwd
2) Execute the command in PHP
EXEC ("sudo useradd user1", $status);
Echo $status;
Change Password: $shell = "Echo 123 | sudo passwd--stdin user ";
PHP Operations Shee Learning notes (a) PHP operation Shell function