Ask Your Question
1

unoconv works from terminal using www-data but not from php script also as www-data [closed]

asked 2013-05-25 11:19:16 +0200

kimsia gravatar image

updated 2015-08-28 10:21:01 +0200

Alex Kemp gravatar image

I wrote the following function in php

public static function convert($originFilePath, $outputDirPath, $toFormat)
{
    $command = 'echo $PATH & UNO_PATH=/usr/lib/libreoffice unoconv --format %s --output %s %s';
    $command = sprintf($command, $toFormat, $outputDirPath, $originFilePath);
    exec($command, $output, $result_var);

    return compact('output', 'result_var', 'outputDirPath', 'originFilePath', 'toFormat');
}

It did not generate any error message, or any pdf file as well.

In terminal, when I run the unoconv directly as www-data, I had no issues.

This is my result after execution:

2013-05-26 03:05:30 Error: Array
(
    [output] => Array
        (
            [0] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
        )

    [result_var] => 1
    [outputDirPath] => /var/virtual/storyzer.com/cake-json/ltequotationapp/webroot/outputfiles/Excel/2
    [originFilePath] => /var/virtual/storyzer.com/cake-json/ltequotationapp/webroot/outputfiles/Excel/2/dsadas.xlsx
    [toFormat] => pdf
)

Please advise.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2015-11-02 02:39:33.174732

Comments

Do you use full paths? Do they contain unicode characters (non-ASCII ones)? What happens when you run your script from terminal as www-data?

mahfiaz gravatar imagemahfiaz ( 2013-05-25 11:57:02 +0200 )edit

this script is part of a framework (cakephp) so it is hard to run it as a standalone script. however, I have no problems running the php -r "exec(unoconv .... )" so I am not sure why this is the case. I am using full paths.

kimsia gravatar imagekimsia ( 2013-05-26 04:53:50 +0200 )edit

@oweng my $PATH is /usr/local/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/node/bin:/opt/node/bin

kimsia gravatar imagekimsia ( 2013-05-26 04:59:28 +0200 )edit

Is it possible to run your cakephp script as www-data to make sure it's not permissions problem?

mahfiaz gravatar imagemahfiaz ( 2013-05-26 08:40:56 +0200 )edit

I have done so, it is not permissions problem

kimsia gravatar imagekimsia ( 2013-05-31 05:49:06 +0200 )edit

2 Answers

Sort by » oldest newest most voted
2

answered 2013-06-03 04:43:44 +0200

kimsia gravatar image

The issue is that I am using Nginx and PHP-FPM.

This means that the PATH is not explicitly declared.

hence causing the issue.

For more details, read http://stackoverflow.com/a/16889381/80353

edit flag offensive delete link more

Comments

Well done on finding a solution.

oweng gravatar imageoweng ( 2013-06-03 04:52:26 +0200 )edit

THis is annoying. I cannot accept my own answer because my points less than 50. And I am continuously prompted to accept an answer for this question. What can I do to circumvent this?

kimsia gravatar imagekimsia ( 2013-06-07 03:38:41 +0200 )edit

I have given you a bit more karma, but it is a site restriction. Does the information in this question help with the messages?

oweng gravatar imageoweng ( 2013-06-08 04:55:36 +0200 )edit

I still have less than 50 karma. Not enough to mark as correct. Somebody please help to mark as correct. This is annoying.

kimsia gravatar imagekimsia ( 2013-06-12 04:31:22 +0200 )edit

Others have recently been marking their answers as correct with less karma, so give it a go and see what happens. There appears to have been a change of policy recently.

oweng gravatar imageoweng ( 2013-06-12 04:35:08 +0200 )edit
0

answered 2013-05-26 03:38:22 +0200

oweng gravatar image

What is your $PATH? This Stack Overflow thread suggests "prepending /usr/local/sbin to the PATH environment variable."

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-05-25 11:19:16 +0200

Seen: 3,058 times

Last updated: Jun 03 '13