PaulClarke's avatar

PHPWord works locally but not when pushed to test server

Dear All,

I am having a problem using PHPWord and I am hoping someone else has experience of this and can let me know where I am going wrong.

Locally, PHPWord is working absolutely perfectly and producing my files as expected.

My settings are:

In composer.json (shortened)

 "require": {
        "php": ">=7.0.2",
        "laravel/framework": "^5.4.17",
        "mpdf/mpdf": "^6.1",
        "phpoffice/phpword": "v0.13.0"
    },

I can also see in my composer.lock that 'v0.13.0' is being used.

I am using fully qualified class names as per the documentation (although it also works fine importing them).

$doc = new \PhpOffice\PhpWord\Phpword();

When I have deployed to my test server and tried to run the file I am getting this error:

production.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Class 'PhpOffice\PhpWord\Phpword' not found in /home/forge/...(myProject)..

Yet when I have checked in the vendor directory on the server, all the files are exactly where you would expect them to be. I have run composer dump-autoload just in case, but no joy.

One more piece of information: elsewhere in my project I have been using mPDF and I can now see PHPStorm saying where I have imported mPDF it is 'undefined' due to a clash with PHPWord's version.

Can anyone suggest what I could try next please?

0 likes
4 replies
Snapey's avatar
Snapey
Best Answer
Level 122

problems like this usually come down to case sensitivity

is PhpWord\Phpword() correct?

1 like
PaulClarke's avatar

@Snapey Thank you, you are absolutely right. I had $doc = new \PhpOffice\PhpWord\Phpword(); when it ought to have been $doc = new \PhpOffice\PhpWord\PhpWord();

haydi80's avatar

Hello everyone,

I have the same problem while using TemplateProcessor.. Locally it works good, but after deploying to the server I get the following error:

Class 'PhpOffice\PhpWord\TemplateProcessor' not found.

In my Controller, I instantiate it like that:

$path = resource_path('TemplateOffer.docx'); $template = new \PhpOffice\PhpWord\TemplateProcessor($path);

I found in another post that I should add the following: include_once base_path('vendor/autoload.php');

Locally it still works, but remotely not..

Can someone help me please.. Thanks

haydi80's avatar

Hello, I just fixed the problem, but I believe it could be better. The problem was in the files under the vendor\composer folder.. The files: autoload_static.php and installed.json were not the same. If I upload the autoload_static.php file to the server, my site falls down!! So, I just added the missing parts in both files and all works fine, my template works perfectly ! The missing parts were according to 'PhpOffice\PhpWord\' of course.. May be this can help someone having the same troubles as me!

Please or to participate in this conversation.