Currently I'm working on a PHP script that can execute shell commands on a linux root server.
I want to give any user with the right password (htacces) the permission to execute this script (it´s for OpenVPN client creation). When i jump to the plesk interface to execute the PHP script in file data manager, i get an internal server error 500. I already changed the permission of the PHP script to 777 for testing purposes.
I also controlled the php.ini to check if shell_exec/proc_open/exec are on the banned function list.
How can i configure the server/php script to have root permissions on the script?
Is it possible to Log-in with root priviliges when exceuting shell commands with a php script?
Thanks in advance.
Have a nice day.
EDIT: The current code is:
shell_exec('cd ' . $path-openvpn-ca);
shell_exec('source ./vars');
$descriptorspec = array(
0 => array("pipe", "r"), // stdin read by child
1 => array("pipe", "w"), // stdout written to by child
2 => array("file", "error.log", "a") // stderr
);
$process = proc_open($path_openvpn-ca. "/build-key.sh LC_1234", $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], PHP_EOL. PHP_EOL. PHP_EOL. PHP_EOL. PHP_EOL. PHP_EOL. PHP_EOL. PHP_EOL. "." . PHP_EOL. "." PHP_EOL. "y" . PHP_EOL. "y". PHP_EOL);
fclose($pipes[0]);
$output = $pipes[1]; // $pipes[0] is the input and $pipes[2] is the error output
}