Hello,
Sorry, but we don't know what could be wrong in the server setup. As it's working using the PHP CLI mode, some Apache or PHP configuration or some missing rw access may be blocking the conversion.
We recommend you to enable the debug option (https://www.phpdocx.com/api-documentation/format-conversion/convert-Word-docx-into-pdf-with-PHP) and check your server logs to find the source of the problem. Also, check if some external tool such as SELinux or similar is enabled.
Regards.