Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ctaljaardt's avatar

Laravel + CDN ( CloudFront )

Hello.

I wanted to know if there is a easy way to set up cloudfront. Im pretty new to laravel and looking for a guide on how i can achieve this. If anyone has sample projects or tutorials on how i can do this, please let me take a look into it.

I have heard that its pretty easy to implement into laravel but i have no experience in this subject so i dont really know how to get started.

0 likes
9 replies
usman's avatar

@ctaljaardt AFAIK, a CloudFront distribution uses your S3 buckets/containers to serve your content. For your bucket management you will need the S3 Flysystem driver on your Laravel end. The CloudFront distribution for a container needs to be configured from your CloudFront Console.

You can use this lesson as starting point: https://laracasts.com/series/whats-new-in-laravel-5/episodes/6

Usman.

3 likes
timo.heil's avatar

You do not necessarily need to connect Cloudfront to an S3 bucket, but you could set it up to use a so called "origin server" instead.

Basically this will map you cloudfront distribution xxx.cloudfront.net to your website www.mydomain.com

Then all you need to do is rewrite the file URLs and links in the markup from e.g. www.mydomain.com/images/image.jpg to xxx.cloudfront.net/images/images.jpg.

Cloudfront will then search for the file at www.mydomain.com/images/image.jpg and distribute it.

2 likes
pmall's avatar

Then all you need to do is rewrite the file URLs and links in the markup from e.g. www.mydomain.com/images/image.jpg to xxx.cloudfront.net/images/images.jpg.

You can also set up your dns so cdn.mydomain.com points to xxx.cloudfront.net.

Then you set your server as the origin server and you just have to change your url from www.mydomain.com to cdn.mydomain.com.

1 like
amjadkhan896's avatar

Is there any way for vue js, So that i run the npm it compiles the files on the cloudfront?

herronj's avatar

@AMJADKHAN896 - you would need some sort of CI/CD to run to do that compile, then put it where ever you pointed your distribution; be it your server a bucket whatever

Please or to participate in this conversation.