I recently implemented a project for one of our customers. They had selected a supplier for their new global food delivery webshop. The web shop was based on PHP 7.0+, Cake PHP and MySQL.

Since we are managing our customer’s Azure subscription we were asked to take care of the web shop hosting. They required a scalable solution and since it was a food delivery webshop, they required different performance levels depending on the time of the day (many people order food on Sunday evening ;)).

An Azure App Service covers such requirements quite well, so we decided to go this route.

There are numerous articles on the web on how to setup different PHP applications on an Azure App Service. Also Cake PHP offers documentation on how to configure the framework to work on an IIS based web server.

So after some configuration and deployment struggles everything was setup and running. The deployment was configured as “Local git repository” so that the supplier could deploy easily via Git.

After some days (and some deployments) the web shop started to crash “sometimes”. The user would just see a HTTP 500 error.

Checking the logs we could see the following error:

FastCgiModule, Notification: EXECUTE_REQUEST_HANDLER, Status: 500, SubStatus: 0, HttpReason: Internal Server Error, Win32ErrorCode: 0x00000000

This error is a very general one that you can get for several reasons when working with PHP and Azure App Services.

So then we checked the PHP logs and found many messages as following:

Error: Fatal Error (1): Trait ‘Cake\View\StringTemplateTrait’ not found in [D:\home\site\wwwroot\vendor\cakephp\cakephp\src\View\Helper\FormHelper.php, line 52]

Given this error message we assumed, that the “StringTemplateTrait” file was not on the file system anymore (maybe due to deployment)… but it was still there!

In the end we found out (Microsoft Support also helped us alot) that dynamic caching features used in the Azure App Service are having conflicts with PHP.

So to solve the error above, please follow the steps:

  1. From Kudu ‘Environment’, verify if WEBSITE_DYNAMIC_CACHE is turned on (value 1), see screenshot for location (it is already “0” here)

CAKE PHP AND AZURE APP SERVICE HTTP 500 ERRORS 1

2. As a workaround, you can turn off WEBSITE_DYNAMIC_CACHE from App settings,
Key: WEBSITE_DYNAMIC_CACHE, Value: 0

CAKE PHP AND AZURE APP SERVICE HTTP 500 ERRORS 2

3. Restart the site after save the setting, and monitor the log, see if the error happens again.

The above workaround caused no performance issues (at least we could not find any).
More on dynamic cache and an additional (yet untested) workaround:

WEBSITE_DYNAMIC_CACHE is a feature on Azure App platform to help improve performance and mitigate file storage fail over issue. However, with current release, for some PHP applications, there is file path conflict between WEBSITE_DYNAMIC_CACHE and Wincache file cache option. Turning off WEBSITE_DYNAMIC_CACHE will somehow impact site performance, there is another combination that may be mitigate it. You can test this,

  1. Create “.user.ini” file in wwwroot, and add this directive, wincache.fcenabled = 0 (You can create a phpinfo page, and verify the change)
  2. Remove WEBSITE_DYNAMIC_CACHE = 0 or change it to WEBSITE_DYNAMIC_CACHE = 1
  3. Make sure “file not found” issue does not appear after the change, you can keep this settings. Performance should be better than no WEBSITE_DYNAMIC_CACHE. The trad off if disabling wincache file cache, but while WEBSITE_DYNAMIC_CACHE is enable, it should have more significant performance improving than Wincache file cache.