I've tried everything from using xelatex on it's own:
, to using both:
xelatex -no-pdf my_file.tex xdvipdfmx my_file.xdv
and also creating a .sh file with the same commands as above and executing that from php.
No matter what I do I get the following result at the end of the output:
Error 256 (driver return code) generating output;  => file my_file.pdf may not be valid.  => Transcript written on my_file.log. )
However, if I do the exact same things as above from the terminal, everything works fine and the pdf is generated successfully.
The server is running on Ubuntu 14.04. I have been struggling with this issue all day and I am out of ideas. If, from php I execute:
xelatex -no-pdf my_file.tex
everything works fine and the .xdv file is generated. So the problem must be with the xdvipdfmx driver that seems to not work well with php. I am not deeply experienced with php and linux to figure out what might go wrong between these two.
Keep in mind that the output, both from running the commands from the terminal and from executing them from php are exactly the same, up to the point where the pdf is file must be create (the last log lines). When I run them from the terminal, it works and I get
Output written on my_file.pdf (1 page).
and when i compile from php I get
Error 256 (driver return code) generating output;  => file my_file.pdf may not be valid.
This is as close as I could get to the problem.
I changed the .tex file into a much simpler layout, and it generated the pdf successfully. So you could say the problem was with the .tex file, but it's still strange why it worked from the terminal and not from php.