简体   繁体   English

PHP shell_exec没有运行

[英]Php shell_exec not running

This code not running when in PHP code called from web. 在从Web调用的PHP代码中,此代码未运行。 but it runs on cli normally. 但它通常在CLI上运行。 chmod of sh file is 777. sh文件的chmod是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. escapeshellarg()请使用escapeshellarg()

$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. 而且./new-openvpn-client.sh不太可能正确解决。 Put the script in a reasonable location like /usr/local/bin/ and provide the full path in the command. 将脚本放在/usr/local/bin/等合理的位置,并在命令中提供完整路径。

This is a permission issue on application executables. 这是应用程序可执行文件的权限问题。 I have resolved through giving true permission to apache user. 我已经解决了通过向apache用户授予真正的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM