Oops, the private WordPress blog I administer during my off hours on an Azure WebApp went dark with 500 Internal Server Error on all web requests.
<Temporary failure to upload media to the blog, pending screenshot>
The App Service built-in Diagnose and solve problems / Diagnostics and Troubleshooting quickly pointed to an error spike in PHP logs for the past 24 hours:
PHP Fatal error: Class 'Twig_Loader_Filesystem' not found
Or variants of the same in PHP Log Analyzer / PHP Error Log Processing Report:
Class 'Twig_Loader_Filesystem' not found in D:homesitewwwrootwp-contentpluginsgallery-by-supsysticvendorRscEnvironment.php on line 171
After PHP update:
Uncaught Error: Class 'Twig_Loader_Filesystem' not found in D:homesitewwwrootwp-contentpluginsgallery-by-supsysticvendorRscEnvironment.php:171
(Note that you need to re-run "Collect PHP Error Logs" each time you want to validate if a change resolved your issue or got you to the next issue to investigate.)
Not clear why this started failing now. Web search lead me to https://twig.symfony.com/doc/2.x/intro.html#installation
Apparently I needed newer PHP in the first place to run Twig. My PHP in the Application Settings was at 5.6 so I jumped to 7.2. That wasn't enough of course, just a pre-req.
Then I needed Composer as installation mechanism. I found it in the App Service Extensions inside the portal. A restart of the App Service and some wait time was required before Composer started working in the Kudu console (I used the PowerShell version of the console).
<pending screenshot of extensions with composer>
The default start folder for the Kudu console doesn't work for Twig installation due to permission denied. I navigated just under site then (I'm unsure if that's the right place to install it, expert recommendation welcome).
PS D:homesite>>composer require "twig/twig:^2.0"
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
- Installing symfony/polyfill-mbstring (v1.7.0): Downloading (connecting...)Downloading (0%) Downloading (20%)Downloading (40%)Downloading (45%)Downloading (65%)Downloading (85%)Downloading (90%)Downloading (100%)
- Installing twig/twig (v2.0.0): Downloading (connecting...)Downloading (100%)
Writing lock file
Generating autoload files