[Php] php running on a linux system, execute system commands

In a recent study of third-party software pdf print function, the need for third-party software to run php command, it took a long time to debug the success of the Internet to find information that is not incomplete copy and paste, simply to make a post of your own

Points

  • exec, system and the like must write instruction execution instruction as an absolute path /usr/local/bin/wkhtmltopdf, with the former instruction sudois not or no path relative path
  • To configure the appropriate permissions sudo, sudo restriction instruction execution rights, configuration visudo (/ etc / sudoers)
// php 测试代码
<?php 
exec('sudo absolute_path/exeName',$out,$result);
echo $result;
// result 输出为0 的时候表示成功,1或者其他表示失败
#  visudo  打开后再末尾追加
apache ALL=(ALL) NOPASSWD:/usr/local/bin/wkhtmltopdf
# PHP执行的用户  网络指定(可以写网址)= (目标) 无密码声明:限制执行的指令
Personal experience, do not like do not spray, reprint please state the source from this site

Guess you like

Origin www.cnblogs.com/china-flint/p/11567502.html