I have a LAMP stack that I am developing a web app that will be used on different servers running different flavors of linux and mac OS.
I want to use the exec() function of php to call the soffice program to convert an ODT to a PDF. However, when you make this call, you have to use the full file path of the program.
On linux it is typically under /usr/bin/soffice, but on Mac it’s under /Applications/LibreOffice.app/Contents/MacOS/soffice.
So my question is, what is the best way to deal with different program locations for the same function call?
I thought about setting a PATH variable on mac and linux in the OS and then just call exec(soffice), but apparently the OS PATH is not transferred to the PHP getenv[‘PATH’].
What is the best way to accomplish running the same program on different platforms which put the same program in different locations?
on both linux and mac you can run
$(which soffice) my-args-here and get the full path to the executable on the current machine.
The other option is to detect on which OS you are currently running and then fire the command with the correct path.
Answered By – Broshi