Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

doc2pdf - unable to connect or start own listener

Tags:

linux

php

debian

command

$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);

output

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

This is a part of an upload script and is running as www-data under Apache..

The command line alone works fine from putty as root

The script has worked under www-data, but now it doesn't? :-/

update I

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

code:

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

error:

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

update II

echo "127.0.1.1 $(hostname)" >> /etc/hosts
reboot
like image 388
clarkk Avatar asked Sep 04 '15 16:09

clarkk


1 Answers

You can either change the owner of /usr/bin/doc2pdf with the 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.

$sudo visudo

add this to the very end of file

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

Save file and you're done. Don't forget to change this line of your php code as well (add sudo at the beginning):

exec('sudo /usr/bin/doc2pdf -o '.$file.'.new '.$file.' 2>&1', $out);
like image 176
Eugene Sue Avatar answered Oct 17 '22 15:10

Eugene Sue