$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.
)
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? :-/
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
echo "127.0.1.1 $(hostname)" >> /etc/hosts
reboot
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With