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 instructionsudo
is 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执行的用户 网络指定(可以写网址)= (目标) 无密码声明:限制执行的指令