-1

I have a php script test.php which invokes latex+biber:

`/usr/local/texlive/2016/bin/x86_64-linux/latex  --interaction batchmode test.tex `;
`/usr/local/texlive/2016/bin/x86_64-linux/biber  test`;

The script works fine if I run it from terminal php test.php (as root); it does not work when it is called from a browser http://localhost/test.php. In the latter case, I understand it is called from user apache. (I am testing on a Linux Fedora 29 machine).

The issue turns out to be related with `biber':

[root@fedora-pc]# su -s /bin/bash apache
bash-4.4$ /usr/local/texlive/2016/bin/x86_64-linux/biber test
Can't open test.blg (Permission denied) at /tmp/par-617061636865/cache-975de9a2a2c44ccaa5329d9695a54026ffc29f68/inc/lib/Log/Log4perl/Appender/File.pm line 151.

Also, I just discovered that

[root@fedora-pc 2019]# /usr/local/texlive/2016/bin/x86_64-linux/tlmgr update --list
/usr/local/texlive/2016/tlpkg/installer/xz/xzdec.x86_64-linux: (stdin): Unexpected end of input

[root@fedora-pc 2019]# tlmgr update --self
/usr/local/texlive/2016/tlpkg/installer/xz/xzdec.x86_64-linux: (stdin): Unexpected end of input
/usr/local/texlive/2016/bin/x86_64-linux/tlmgr: checksum error when downloading /tmp/WQEchRh21D/TzyO2wJ8pA from http://ftp.rrze.uni-erlangen.de/ctan/systems/texlive/tlnet/tlpkg/texlive.tlpdb: digest disagree

I am not so knowledgeable about LaTex to know what is going on and how to fix it. (biber is version 2.9)

mario
  • 761
  • It looks as though Biber is not allowed to write its log file (the .blg). If I'm not mistaken, Biber will try to write the .blg in the current working directory. Not sure what that would be in your case, but it might be in a place where you have no write permissions. The other errors have nothing to do with Biber and are TeX live infrastructure-related. TeX live 2016 is frozen and doesn't get any updates any more (just about current is TeX live 2018, TeX live 2019 should be released around May). – moewe Apr 13 '19 at 18:13
  • 1
    It would be interesting to know if the LaTeX run works properly, I would have expected it to face similar permission issues with the .log file and all the auxiliary files. It should be noted, though, that Biber unpacks its executable into a temporary directory (in your case /tmp/par-617061636865/cache-975de9a2a2c44ccaa5329d9695a54026ffc29f68/) and runs from there. If programs in that path are restricted compared to programs in /usr/local/texlive/2016/bin/x86_64-linux/ and elsewhere (and it might not be unreasonable to apply such restrictions), that could explain things. – moewe Apr 13 '19 at 18:22
  • Related question on Windows: https://tex.stackexchange.com/q/406960/35864. There it turned out that Bitdefender was blocking Biber (maybe even due to a heuristic that took issue with executables coming from a temporary folder). – moewe Apr 13 '19 at 18:27
  • @moewe LaTeX run works properly. How do I check whether 'programs in that [tmp] path are restricted'? – mario Apr 13 '19 at 20:12
  • Sorry, no idea, that would be more of a Linux question than a LaTeX question, I guess. – moewe Apr 14 '19 at 04:04
  • the Tex/Biber questions is whether or not I may configure Biber as not to run from /tmp/ – mario Apr 14 '19 at 08:22
  • Also, I just discovered that if I change owner of the /tmp/par/ directory to apache, and run biber as root, I just get .../biber: private subdirectory /tmp/par-726f6f74 is unsafe (please remove it and retry your operation). – mario Apr 14 '19 at 08:30
  • Biber uses PAR::Packer to unpack, apparently there is an environment variable to change the cache location: https://www.perlmonks.org/?node_id=709846. Re your error message: https://www.perlmonks.org/?node_id=1058025 – moewe Apr 14 '19 at 08:34
  • Thanks, but I would rather not go into Perl. I would hope just to pass a different option to Biber. – mario Apr 14 '19 at 08:53
  • I am not aware of any Biber option you could use, sorry. In https://github.com/plk/biber/issues/70 the Biber developer mentions PAR_GLOBAL_TEMP himself, so I guess this is the intended interface. – moewe Apr 14 '19 at 08:55
  • do you happen to know how I could set PAR_GLOBAL_TEMP to my web server folder? – mario Apr 16 '19 at 21:54
  • PAR_GLOBAL_TEMP should be a normal environment variable. It can be set and read like other variables such as PATH, HOME, TEMP, ... If and how this can be done will depend on your server and your rights (but I would not know anything about that, I'm afraid). – moewe Apr 17 '19 at 11:39
  • If you found a solution, please post a proper answer in the answers section and accept it so others can find it more quickly and benefit from it as well. (Personally, I think it should not be necessary to run Biber with root rights, but that there should instead be a way to redirect its temporary folder to a place where a normal user has read and write permissions, but I would not know how to do that.) – moewe Apr 18 '19 at 11:29
  • Hi, I fixed it! In the sudoers file I added line apache ALL=(ALL:ALL) NOPASSWD:/...path.../biber; hence within the php script I call biber by sudo -u root /..path.../biber bibFile. The trick is to sudo on root (thanks) . I note that the latter is not needed to call (pdf)latex. I have set PAR_GLOBAL_TEMP to /var/www/tmp/ too, but it does not help. Also, Biber does not sem to unpack its executable when called as above, it does when called from terminal. – mario Apr 18 '19 at 11:30

1 Answers1

0

Linux Fedora 29, 4.19.12-301.fc29.x86_64; pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (I updated)

I fixed my issue when I added the following line to the sudoers file:

apache ALL=(ALL:ALL) NOPASSWD:/usr/local/texlive/2018/bin/x86_64-linux/biber

My script test.php is:

<?php

$NomeFile = 'test';
$bibFile = $NomeFile;
$texFile = $NomeFile.".tex";
$pdfFile = $NomeFile.".pdf";
$f=fopen($texFile,'w');

            $header ="\\documentclass{article} \n ";
            $header.="\\usepackage[latin1]{inputenc} \n ";
            $header.="\\usepackage[T1]{fontenc} \n ";
            $header.="\\usepackage[american,italian]{babel} \n ";
            $header.="\\usepackage[babel,italian=guillemets]{csquotes} \n ";
            $header.="\\usepackage[backend=biber,sorting=ynt]{biblatex}\n";
            $header.="\\usepackage[pdftex]{hyperref} \n ";

            $header.= "\\bibliography{".$bibFile."}";
            $header.="\\begin{document} \n ";

            $f=fopen($NomeFile.'.tex','w');
            fputs($f,$header);

fputs($f,"\\cite{Mario}"); 
$printbib = '\\printbibliography';
fputs($f,$printbib);
fputs($f,"\\end{document}");
fclose($f);

$filenameTeX = $NomeFile.'.tex'; 
$test_2 = `/usr/local/texlive/2018/bin/x86_64-linux/pdflatex  --interaction batchmode $texFile `;
$test_3 = `sudo -u root /usr/local/texlive/2018/bin/x86_64-linux/biber  $bibFile `;
$test_4 = `/usr/local/texlive/2018/bin/x86_64-linux/pdflatex  --interaction batchmode $texFile `;

$filenamePdf = $NomeFile.'.pdf'; 
echo "2 <pre>$test_2</pre>";
echo "3 <pre>$test_3</pre>";
echo "4 <pre>$test_4</pre>";
echo "<br><a href=\"$filenamePdf\">$filenamePdf</a>";
echo "<br><a href=\"$filenameTeX\">$filenameTeX</a>";
?>

my .bib file

@BOOK{Mario,
  author =      {Mario Doe},
  title =       {TITLE},
  publisher =   {My Pubblisher},
  location =    {World},
  year =        {2025} 
 }

I have set PAR_GLOBAL_TEMP=\var\www\tmp too, tmp owned by user apache, but it did not help.

A call from my browser http://localhost/test.php produces the wished test.tex and test.pdf files, bibliography included. /var/www/tmp/ remains empty. The same if I try by either [root@....]# php test.php or

[root@...]# su -s /bin/bash apache
bash-4.4$ php test.php

Note, if later I compile the .tex file, then /var/www/tmp/ gets polluted by a number of files, mainly within a inc sub-directory.

I am not sure this is the best solution, still it works for me, on a local settings.

mario
  • 761