Converting doc to pdf using libreoffice?

I am trying to convert doc to pdf through linux command using libreoffice support. When I login to ssh and try the command it creats the pdf on root access. But the same is not working with the webserver(apache user).
Here is the command I am running.
"/usr/bin/libreoffice --headless --convert-to pdf /path/localfile -outdir /outputdir"
My idea is to create a wp plugin.