# mktextfm fails when pdflatex is invoked by cgi-bin script under www-data (apache)

I'm starting `pdflatex` from a shell-script invoked as cgi-bin application on Ubuntu (running under default `www-data` user) and from time to time I have the following kind of error preventing compiling:

``````kpathsea: Running mktextfm larm0700
mktextfm: mktexdir ./.texmf-var/fonts/tfm/lh/lh-t2a failed.
kpathsea: Appending font creation commands to missfont.log.

./thebook.tex:330: Font T2A/cmr/m/n/7=larm0700 at 7.0pt not loadable: Metric (T
relax
l.330 10 м/с\textsuperscript{2}

./thebook.tex:330:  ==> Fatal error occurred, no output PDF file produced!
Transcript written on thebook.log.
``````

Inspection shows that an empty directory `.texmf-var/fonts/tfm/lh/lh-t2a` created in a working dir (in contrast with `mktexdir` message).

Running the same script with `sudo -u www-data` fixes the problem temporary: fonts are generated and then this particular document can be compiled from the cgi-bin script. But it does not provide stable result: as new fonts are needed, cgi-bin script stops working again.

The similar problems are discussed also here, here, here, here, here (in Russian), here and maybe somewhere else, but no clear solutions provided.

``````export HOME='/var/www'
to the shell-script just before the `pdflatex` command.