Situation
I just installed OpenEMR on my Mac. I went through the installation steps in my browser and I clicked to start using OpenEMR but it failed with a list of “Deprecated” errors and one final “Parse” error. The Parse error is:
Parse error : syntax error, unexpected token “:” in /usr/local/var/www/openemr/vendor/twig/twig/src/Environment.php(361) : eval()'d code on line 98
Operating System
I’m using: MacOS Sequoia Version 15.2
Search
Did you search the forum for similar questions? Yes
Logs
Did you check the logs? No. Don’t know where to find them.
Was there anything pertinent in them?
Please paste them here (surround with three backticks (```) for readability.
You can also turn on User Debugging under Administration->Globals->Logging User Debugging Options=>All
I edited the php.ini file to turn display errors off but now it just crashes. I think the syntax error it finds in Environment.php is causing the crash.
Turn off deprecated error reporting in php.ini config. Unsure if in install doc but I thought it was.
Search and find error_reporting and edit to below. Will report errors and warnings. This is a must!
If you have a .htaccess file in the OpenEMR root directory, there could be issues in its configuration. Temporarily disable it by renaming it and checking if the issue persists.
Ensure that your PHP settings are correctly configured. Common problems might include issues with PHP version compatibility or memory limits.
Check your PHP version (OpenEMR typically supports PHP 7.2+).
Review your php.ini settings for issues like memory_limit, max_execution_time, etc.
Check the PHP error log: /var/log/php_errors.log.
5. Database Connection
An error 500 can also occur if OpenEMR cannot connect to the database. Ensure your database is running and that the credentials in sites/default/sqlconf.php are correct.
6. Apache Restart
After making changes to any configuration, restart Apache:
sudo systemctl restart apache2
7. Check for Missing Dependencies
Ensure that all required PHP extensions are installed. Common required extensions for OpenEMR include:
In the apache error log, I see the following error:
Parse error : syntax error, unexpected token “:” in /usr/local/var/www/openemr/vendor/twig/twig/src/Environment.php(361) : eval()'d code on line 98
This is the same error as I get in the browser when “display_errors = On” is set in php.ini.
When “display_errors = Off”, the server crashes with the HTTP 500 error. This leads me to believe that the reported Parse/Syntax error is the underlying cause.
I had a look at Environment.php (line 361) and this is what I see:
355 if (!class_exists($mainCls, false)) {
356 /* Last line of defense if either $this->bcWriteCacheFile was used,
357 * $this->cache is implemented as a no-op or we have a race condition
358 * where the cache was cleared between the above calls to write to and load from
359 * the cache.
360 */
361 eval(‘?>’.$content);
362 }
I added an echo statement to print out the $content before the eval(). It looks like this:
I’m not sure how to interpret this. To my untrained eye, there is no “:” there that stands out as misplaced. I’m also not sure how to interpret the “on line 98” in the error message from eval().
Perhaps I am barking up the wrong tree but it seems that the eval() function is trying to process some text as php code that it doesn’t like.
I’m open to further suggestions and I’ll see if I can try installing on a different computer and with a different version of OpenEMR.
@John_Kildea do you have docker on your mac? That might be the easiest route to get up and running. I haven’t heard much from mac users recently of running OpenEMR on the bare metal, although I would have thought it’d work.
What version of PHP are you using? OpenEMR 7.0.2 requires php 8.1.0 (not php 7.2 as was earlier mentioned).
Thanks @adunsulag and @stephenwaite for the suggestions. I did try the Docker route but as I’m not familiar with Docker, I got confused about how to connect the OpenEMR container with a MySQL container. As a result, I didn’t get very far. I’d like to explore this again in the future as it does seem like the most elegant route.
I did some Googling and found this thread on Github with the same Environment.php issue that I was having with Twig: Issue with Environment.php at line 358 eval() after PHP 8 update. · Issue #3915 · twigphp/Twig · GitHub. This suggested that there was an issue between Twig and PHP 8.x. Perhaps it is only an issue on Mac if others aren’t reporting it for OpenEMR. Although it was for a different product (ie not OpenEMR), it was exactly the same issue as I was having. This suggested to me that there was a real problem with Twig.
So, I replaced the Twig that is shipped with OpenEMR in the vendor folder with the latest version from Twig’s github. It did the trick! I am now able to use a bare-metal-installed OpenEMR on Mac in my browser.
Perhaps it may be worth using the latest version of Twig in the next version of OpenEMR?
No, I upgraded to Twig 3.18.0. I just did a git clone to the default current version from the Twig github.
For PHP, I am using version 8.4.2. However, over the last few days I cycled through various versions of PHP trying to see if any would work. I kept getting the same Environment.php syntax error until I upgraded Tiwg.
Exactly, I just did a clone of the Twig github on my Mac and slotted the resulting folder in place of the twig/twig folder of OpenEMR. As I was just trying it to see and as I don’t have experience with composer, I just did the cloning.
Indeed, it seems to be a pre-release of Twig 3.18.0. I got the version number from the CHANELOG. If you look at their CHANELOG on Github, you can see that they are actively adding to the 3.18.0 list and it doesn’t yet have a release date.
I’ll be happy to help test PHP 8.4 if I can be of use.
hi @John_Kildea, we’re able to test php8.4 now that Brady has fixed up the dockers to work. It’s easiest to follow the contributing guide and play around with the easy dev environment that’s described there. Thank you and good luck!