简体   繁体   中英

Is it possible to use AWS CloudFront for PHP files?

I'm trying to load PHP files such as index.php using AWS CloudFront.

The documentation states -

Create a web distribution if you want to:

Speed up distribution of static and dynamic content, for example, .html, .css, .php, and graphics files. Distribute media files using HTTP or HTTPS. Add, update, or delete objects, and submit data from web forms. Use live streaming to stream an event in real time.

However, when I upload PHP files to the relative CloudFront bucket it ends up downloading the file and opening it. How will allow me to host PHP files?

However, when I upload PHP files to the relative CloudFront bucket

There is no such thing as a CloudFront bucket , so you are likely referring to an S3 bucket, configured behind CloudFront as an origin.

CloudFront works with dynamic content, such as might be generated with PHP, but the PHP site needs to be hosted on a server that supports it -- not S3.

You can host a static website on Amazon Simple Storage Service (Amazon S3). On a static website, individual webpages include static content. They might also contain client-side scripts. By contrast, a dynamic website relies on server-side processing, including server-side scripts such as PHP , JSP, or ASP.NET. Amazon S3 does not support server-side scripting. (emphasis added)

https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html

See AWS Web Site Solutions for options for hosting sites involving static or dynamic content, bearing in mind that PHP requires a solution supporting server-side scripting and dynamic content, so not all solutions presented there (including S3) will fit your needs... but these are all compatible with CloudFront -- which is only tasked with delivering the rendered content, not the original rendering.

CloudFront is designed to serve content to end users and not execute your code. Your PHP files would be on an EC2 instance running PHP and a webserver (Apache, Nginx) which you could then put behind CloudFront to get the benefits. This would then generate the HTML for CloudFront to serve. CloudFront itself does not handle the processing and just deals with the static HTML. When using CloudFront with S3 it will serve up the content directly to the end user.

I am not quite sure where you found that snippet but the introduction does not seem to list .php for me.

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html

Amazon CloudFront is a web service that speeds up distribution of your static and dynamic web content, such as .html, .css, .js, and image files, to your users.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM