doc2pdf - 无法连接或启动自己的侦听器

doc2pdf - unable to connect or start own listener

命令

$file = '/var/www/test.docx';
move_uploaded_file($uploaded_file, $file);
echo 'is file: '.is_file($file)."\n";

exec('/usr/bin/doc2pdf -o '.$file.'.new '.$file.' 2>&1', $out);
print_r($out);

产出

is file: 1
Array
(
    [0] => Error: Unable to connect or start own listener. Aborting.
)

这是上传脚本的一部分,在 Apache 下 运行 为 www-data..

单独使用命令行在 putty 中工作正常,如 root

脚本在www-data下可以运行,现在不行了? :-/

更新我

apt-get install sudo
sudo visudo # added "www-data ALL = NOPASSWD: /usr/bin/doc2pdf"

代码:

exec('sudo /usr/bin/doc2pdf -o '.$file.'.new '.$file.' 2>&1', $out);
print_r($out);

错误:

sudo: unable to resolve host dyntest-amd-3700-2gb

更新二

echo "127.0.1.1 $(hostname)" >> /etc/hosts
reboot

以 root 身份连接到 ssh

sudo visudo

添加

www-data ALL=(ALL) NOPASSWD: /usr/bin/doc2pdf

并保存 :wq

您可以使用 chown command, or change the privileges of www-data user allowing to run commands as root without entering password. To do this, you'll have to edit /etc/sudoers file. Better not to edit it derectly, though. There's an util in linux used for this: visudo 更改 /usr/bin/doc2pdf 的所有者。

$sudo visudo

将其添加到文件的末尾

www-data ALL = NOPASSWD: /usr/bin/doc2pdf

保存文件,大功告成。不要忘记也更改 php 代码的这一行(在开头添加 sudo):

exec('sudo /usr/bin/doc2pdf -o '.$file.'.new '.$file.' 2>&1', $out);