This project has moved. For the latest updates, please go here.

Command runs properly in shell but not when executed through php via shell_exec

Jun 16, 2014 at 10:29 AM
The command works absolutely fine when run through shell.
But when I try to run through php using shell_exec, it gives me the following error and does not successfully complete document conversion
ERROR - Object reference not set to an instance of an object. Did not convert

May I know where I am wrong..
Coordinator
Jun 16, 2014 at 11:45 AM
Hi

This is probably down to the web server user that PHP is running under not having sufficient permissions to start the Office applications.

Follow the steps described at http://www.figured-it-out.com/figured-out.php?sid=24 to allow the user PHP runs under to start the Office applications.

Note that there are potential security issues associated with allowing PHP to start Office applications (e.g. anonymous users being able to run macros on your server).

Regards
Vittal
Jun 16, 2014 at 12:04 PM
Thanks a lot !!

Just a question - If I use Libreoffice to get my docs converted to pdf (again by the web server user), will then the security issues still be there..?
Coordinator
Jun 16, 2014 at 12:19 PM
Hi

With LibreOffice, you can choose whether to load the Visual Basic for Applications (VBA) code from MS Office documents (https://help.libreoffice.org/Common/VBA_Properties). If you disable loading of VBA code, then you will prevent MS Office applications running code. However, if users are submitting native LibreOffice files, then they can still run macros unless you set the Macro Security settings in LibreOffice appropriately.

If you use Office to convert documents, you should consider locking down Macro security in each application such that macros don't run, or only trusted/signed macros run.

Note that LibreOffice may not produce PDF documents that closely match the layout of the original MS Office document.

Regards
Vittal
Jul 18, 2014 at 11:38 AM
Hi,
I am facing a similar issue,were you able to resolve this issue.

Thanks,
Ranjan
Jul 18, 2014 at 12:08 PM
Hi Ranjan,

Vittal said it quite right above. There are permission issues.
To answer your question, I was not able to figure out.




Jul 18, 2014 at 1:15 PM
So were able to fix "ERROR - Object reference not set to an instance of an object. Did not convert" by following steps in the below article?

http://www.figured-it-out.com/figured-out.php?sid=24
Jul 18, 2014 at 2:02 PM
Sorry, but actually I have not tried it.



Nov 6, 2014 at 9:33 AM
Edited Nov 6, 2014 at 9:34 AM
Same problem here!

Running on windows 8, wamp. If execute from cmd works fine, but not with php exec. For sure is a permissions problem but we can't find a solution. We tried also to call our php script thru php.exe but no luck.

(Tried http://www.figured-it-out.com/figured-out.php?sid=24 and not works)
Coordinator
Nov 9, 2014 at 7:06 PM
This blog post http://www.timwappat.info/post/2013/09/02/Solution-to-Excel-Automation-VBNETC-error-running-as-a-service-0x800A03EC-MicrosoftOfficeInteropExcelWorkbooksOpen describes the permissions needed for Excel automation through ASP. The same DCOM and filesystem changes listed in the post could well be required for all the Office applications in order to use officetopdf via a web server.

Regards
Vittal
Nov 21, 2014 at 3:36 PM
did anyone figured it out?
im having the same problem, running fine from cmd, but not using php exec
Nov 22, 2014 at 10:30 AM
if anybody is still struglling with the isuue, evetaully what i did was to in the dcom permissions of the word apllication, i went to the identity tab and changed it to the interactive user
Nov 22, 2014 at 11:36 AM
Hi,

As danielkatzan said, I have resolved the issue also changing dcom permissions of word applocation into the identity tab
Mar 7, 2015 at 10:12 AM
Hi, although we manage to make it work on a windows 8. Now we are trying to make it work and we can't get it work for a permission problem. Here is the workaround and tested in two different servers:

I resume all step by step:

Objective:
PHP example file (testing: i.php) must be able to exec(‘officetopdf.exe input.doc output.pdf’).

Problem:
when executed it throw the error

‘Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied.’

and do not execute properly.

Information:
⁃   The server has IIS and plesk panel. The user that calls PHP has been created with Plesk.
⁃   When officetopdf.exe is executed directly with cmd.exe it works well as expected.
⁃   It seem to be a problem of permissions of DCOM
⁃   On local environment on our office in another computer with windows 8 changing DCOM permissions it worked well.
⁃   On first install of office in the server all DCOM applications do not appear in DCOM config panel. I don’t remember how we added but it wasn’t automatically added because the Office was 32 bit and the system is 64 bit. If office 32 bit is installed the error ‘Retrieving the COM class factory’ changes to something like it do not find the class.
⁃     Tested on 2 servers windows 2012
Hope someone knows about this issue or maybe could help someone!
Best regards!
Mar 10, 2015 at 9:26 AM
We figure what the problem was... If you are running your officetopdf.exe from a IIS user it causes that permission problem. We couldn't manage to make it work with IIS so we installed wamp and executing exec(‘officetopdf.exe input.doc output.pdf’) from php wamp it works as expected changing the dcom permissions.

best regards!