Search code examples
phplaravelamazon-cloudfrontcontent-delivery-network

How do I setup Cloudfront CDN for Laravel application?


We have developed a Laravel application which is working fine. Once we enabled CDN (Amazon Cloudfront), it stopped working all forms. Wherever there is a form submissions like Login, Contact us , etc. It's not at all working.

We have identified that there should be some changes we have to do for Laravel applications, we are looking for help from some experts who have successfully configured Laravel application with CDN.

We are using PHP 7.1.20 and Laravel 5.4 versions.


Solution

  • I think you misunderstand the use of CloudFront as a CDN, or any CDN for that matter.

    You don't put it in front of your whole site - it doesn't serve your site. It serves as cache for your static assets: your media, stylesheets and scripts. Everything else is still served directly from your PHP application.

    You can set the ASSET_URL environment variable for your application and Laravel will use that to point to your assets when you use the asset() or mix() helpers.