I am trying to create a Word doc in php (7.4) and am using PhpWord 0.18.2. All goes fine right up until I save the document. The system throws an HTTP 500 (Internal sever error). I have searched for this but could not find anything on it. Googleverse and StackOverflow keep pointing me to the follow (or similar) code and none of the results deals with my issue (that I could find). Here it is:
<?php
echo(__FILE__ . ' ' . __LINE__ . '<br />');
include('../vendor/autoload.php');
echo(__FILE__ . ' ' . __LINE__ . '<br />');
$phpWord = new \PhpOffice\PhpWord\PhpWord();
echo(__FILE__ . ' ' . __LINE__ . '<br />');
// Create the new document..
$phpWord = new \PhpOffice\PhpWord\PhpWord();
echo(__FILE__ . ' ' . __LINE__ . '<br />');
// Add an empty Section to the document
$section = $phpWord->addSection();
echo(__FILE__ . ' ' . __LINE__ . '<br />');
// Add Text element to the Section
$section->addText(
'Hello World!.'
);
echo(__FILE__ . ' ' . __LINE__ . '<br />');
// Save document
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
echo(__FILE__ . ' ' . __LINE__ . '<br />');
$objWriter->save('HelloWorld.docx');
echo(__FILE__ . ' ' . __LINE__ . '<br />');
I have used the echo statements to determine where the system fails. Here is the output:
/var/www/intra/modules/ViventiumFMLAEligibility/PhpWordTest.php 2
/var/www/intra/modules/ViventiumFMLAEligibility/PhpWordTest.php 4
/var/www/intra/modules/ViventiumFMLAEligibility/PhpWordTest.php 6
/var/www/intra/modules/ViventiumFMLAEligibility/PhpWordTest.php 9
/var/www/intra/modules/ViventiumFMLAEligibility/PhpWordTest.php 12
/var/www/intra/modules/ViventiumFMLAEligibility/PhpWordTest.php 17
/var/www/intra/modules/ViventiumFMLAEligibility/PhpWordTest.php 20
NOTE: I have tried it without the echo statements (my search mentioned that the file will be corrupt with any echo/print_r statements). In both cases, it throws the 500 error.
This has to be something simple, but I just can't see what the issue is. The console isn't much help. Any advice on how to troubleshoot 500 errors is welcome. I'm no sys admin, so a little hand-holding would be appreciated.