June 10, 2018
419 (Internal Server Error) Response from AJAX requests running Laravel on Google Cloud Platform

After using Firebase applications for app development over the last few months, I decided to move some of my other web apps to Google Cloud Platform. While it’s definitely a bit overwhelming at first, the speed, autoscaling, and deployment have really made it nice to work with.

However, I quickly ran into multiple hurdles when deploying my Laravel applications to Google App Engine. Majority were quick fixes, but the one mentioned in this post was a bit of a ahead scratcher at first. All of my AJAX requests from axios, etc., were returning a Failed to load resource: the server responded with a status of 419 (Internal Server Error) error. The issue seems to arise from the default file session driver used by Laravel not being able to write to disk. While you can most likely just change directory permissions using the post-install-cmd hook in composer.json or using a database for session storing (both viable options to fix the error), Redis has proven itself much faster for session handling in my applications, and it made sense since I was already using it for caching data throughout my applications. I fired up a Redis Cloud Memorystore instance and modifed my app.yaml file with the settings below.

Modified app.yaml environment variables:

SESSION_DRIVER: redis
REDIS_HOST: [local ip address to redis instance]
REDIS_PORT: 6379

Hope this helps you get back to 200!

Copyright © 2022 Allan Kiezel – Long Island Web Designer & App Developer. All rights reserved.