Libreoffice can't find Java on ubuntu server

I’m trying to run the following command using Symfony inside of a controller that I have (laravel):

"soffice --safe-mode --convert-to pdf store/file.docx --headless

It works in commandline but not when run through the controller. I thought it might be a permissions issue at first but now I keep getting this error about java:

Exit Code: 77(Unknown error)↵↵Working directory: /var/www/project/public↵↵Output:↵================↵↵↵Error Output:↵================↵javaldx failed!↵Warning: failed to read path from javaldx↵LibreOffice 6.2 - Fatal Error: The application cannot be started. ↵User installation could not be completed. ↵"
trace: [{function: "getHigherPDF", class: "App\Http\Controllers\AssessmentController", type: "::"},…]

so I’m thinking that it can’t find java for some reason? Where can I update the path to my correct instance of java if that’s the issue?

When i do which libreoffice it says i’m using /usr/bin/libreoffice, but when i try to find a place to updat the java path in there I’m afraid to edit because it’s not super clear where the path is defined

edit: i’ve tried installing libreoffice-base and it didn’t help

Some questions, and no guarantee that answering them would help at all.

  • Why --safe-mode?
  • Why Java is needed at all? do you have Java-dependent plugins with your LibreOffice? otherwise, for a docx import and pdf export, there shouldn’t be a need for Java.
  • How is LibreOffice installed? PPA? Snap? TDF DEB?
  • I was attempting to use --safe-mode because of a certain thread I found where someone was having a similar error, but i get the same result without --safe-mode as well, it made no difference
  • I don’t think I DO need Java, but I get this error even though all i’m running is the pdf convert. is there a way to have libreoffice stop looking for java completely?
  • I installed it using ppa

@mike kaganski I see here that there is a way to turn off java for libreoffice through the gui, is there a way to turn it off via terminal if I’m running it on a remote server where I can’t have a gui? Can I use Libre Office without java?

Posted an answer a few days back to help resolve a similar error. Don’t know if it solved that problem, or if it’ll solve this one, but it might help… Can't run Libreoffice at all - Crash at the beginning

I had to give www-data the correct home directory!!

 $process = new Process("HOME=".getCWD()." && export HOME && libreoffice --headless --convert-to pdf store/mar_maribov_higher_results.docx --outdir store");
        $process->run();
        return $path_copy_pdf;