Different output when compile from PHP and from console

I am creating cards with tasks in tex format. Card sample

\documentclass[14pt]{book}
\usepackage{color}
\usepackage[utf8x]{inputenc}
\usepackage[T2A]{fontenc}
\usepackage[english,russian]{babel}
\usepackage{ucs}\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\pagestyle{empty}
\begin{document}
Карточка №1
\begin{equation*}\text{Решите уравнение}\space \log_{9}{(4x+5)}=5           \end{equation*} \\
\begin{equation*}\text{Решите уравнение}\space \log_{4}{(4x+(-1))}=4 \end{equation*} \\
\begin{equation*}Решите\space уравнение\space \log_{2}{(1x^2+(-2))} = \log_{2}{6x} \end{equation*} \\
\begin{equation*}\text{Решите уравнение}\space \log_{4}{x} = 5 \end{equation*} \\
\begin{equation*}\text{Решите уравнение}\space \log_{7}{x} = 2 \end{equation*} \\
\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
\end{document}

When I compile this file via shell_exec in PHP, resulting PDF doesn't have any letters, just formulas. But, if I run /usr/bin/pdflatex -output-directory /var/www/files --interaction batchmode 2016-06-15.00-30-46576031369d029.tex in console, PDF will contain symbols.

What can cause this problem?

• Perhaps your php and shell is not using the same latex installation. Look in their log files. Btw: are you sure utf8x and us should be used and not just utf8? – daleif Jun 14 '16 at 17:32
• @daleif nope, in php I execute same command. Just looked at log files and I think this is the cause ! Font T2A/lmr/m/n/10=larm1000 at 10.0pt not loadable: Metric (TFM) file not found. – Rulisp Jun 14 '16 at 17:44
• The www user (or whatever is used by PHP) has no “personal tree” where storing the TFM files for Cyrillic fonts. When you do it from your personal account, they are written under ~/.texmf – egreg Jun 14 '16 at 17:49
• @egreg is there any way to bypass it? Switch php user ? – Rulisp Jun 14 '16 at 17:52
• You have somehow to make the tfm available files in the “global” directories. – egreg Jun 14 '16 at 17:58

$output = system("echo 'pass' | sudo -u user /usr/bin/pdflatex -output-directory /var/www/files --interaction batchmode files/".$name.".tex");