This code not running when in PHP code called from web. but it runs on cli normally. chmod of sh file is 777.
$c = shell_exec('printf "{$res}" | ./new-openvpn-client.sh {$user}');
This code not running when in PHP code called from web. but it runs on cli normally. chmod of sh file is 777.
$c = shell_exec('printf "{$res}" | ./new-openvpn-client.sh {$user}');
As mentioned in the other answer, a single quoted string will not parse variables, so you need to use double-quoted. But you also need to ensure the arguments to your external commands are properly quoted and sanitized. Use escapeshellarg() for that.
$res = escapeshellarg($res);
$user = escapeshellarg($user);
$c = shell_exec("printf $res | ./new-openvpn-client.sh $user");
And it's very unlikely that ./new-openvpn-client.sh is going to resolve properly. Put the script in a reasonable location like /usr/local/bin/ and provide the full path in the command.
This is a permission issue on application executables. I have resolved through giving true permission to apache user.