Convert .docx to pdf from PHP on OS X

I am trying to convert .docx files from PHP on OS X Snow Leopard and I keep getting the error message:

kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
2013-05-16 06:45:25.065 soffice[1763:907] Error (1002) creating CGSWindow

I’m using the following code to call LibreOffice and initialize the conversion


"chdir(’/Applications/LibreOffice.app/Contents/MacOS’);

$myCommand = “./soffice --headless --accept=‘socket,host=127.0.0.1,port=8100;urp;’ --convert-to pdf /docfiles/$name --outdir /pdffile/ --nofirststartwizard”;

shell_exec($myCommand);"


Works fine when using terminal.
I understand that it is permission issue of sorts where OS X is preventing the _www apache user from starting an application of the admin user.

I am using version 4.0.3

Any guidance that can provided on how to resolve this will be greatly appreciated.

There are several possibilities.

  1. You could add _www user all necessary permissions. This is not really safe.

  2. You could run apache as your user. Not safe either.

  3. You could create a daemon script which runs as user and watches for a directory and exports everything it finds and moves results to another directory.

  4. The daemon could be listening on localhost:whateverport and recieve info about what to convert from the socket.