Moving PHP e-commerce to CloudFront safely
Migrating a PHP e-commerce site to a CloudFront CDN does not require rewriting the application or moving every workload to serverless. CloudFront can become the public entry point, serve cacheable pages and assets from edge locations, and forward requests that need the application to the existing origin. PHP remains responsible for carts, orders, accounts and administration.
For an Australian store, the benefit is tangible. Sydney, Melbourne, Brisbane and Perth shoppers should receive cached content closer to their connections, while the origin can remain in one of AWS’s Australian regions near the core customer base. Test with NBN, mobile and fixed-wireless connections rather than treating a connection to a local datacentre as representative.
Peak trading changes the risk profile. Click Frenzy, Black Friday, Cyber Monday and EOFY sales can send a normal catalogue from a manageable load to a sudden surge of origin requests. A staged migration, with explicit cache rules and a rollback path, is more valuable than squeezing the last few milliseconds from the homepage.
Designing the cache around storefront behaviour
Start by separating traffic into two classes. Anonymous landing pages, category listings, product pages and versioned CSS, JavaScript, images and fonts are candidates for caching when the response is the same for everyone. Carts, logins, checkout, account pages and order status should continue to reach PHP, usually with caching disabled. CloudFront normally caches eligible GET and HEAD requests, so POST traffic such as basket updates is excluded by design.
Managed cache policies are preferable to scattered legacy settings, but verify the application’s Cache-Control and Expires headers. Keep query strings only when they change the resource, and do not let session identifiers appear in cacheable query strings. Treat responses that set a session cookie as private, then test the exact configuration with baskets, discount codes and logged-in accounts.
Use signed URLs or signed cookies for protected downloads, and give static media a separate origin path so its lifetime can be tuned independently. An origin in Sydney or Melbourne keeps application traffic within Australian infrastructure, but edge cache locations do not make privacy compliance automatic. Review the Australian Privacy Principles, contractual obligations and where personal data is processed. CloudFront remains a delivery layer, not a PHP runtime: the origin still needs capacity and healthy database connections. An origin shield can collapse repeated misses onto one upstream tier when traffic is distributed widely.
Preparing the PHP origin for edge traffic
The target topology can stay conventional. Route 53 resolves the hostname, CloudFront handles public TLS and applies cache and WAF policy, and an ALB sends dynamic requests to ECS or EC2 running PHP, which uses RDS. This keeps the migration focused on delivery rather than an application rewrite.
Configure the origin to handle CloudFront requests correctly. Preserve the Host value expected by the load balancer, set up trusted proxy handling in PHP, and use X-Forwarded-For only when it arrives through a known load balancer or CloudFront path. Restrict the load balancer or web server to CloudFront traffic so attackers cannot bypass WAF rules by addressing the origin directly.
For a custom hostname, attach an ACM certificate to the distribution, and use HTTPS between CloudFront and the origin even when the origin sits inside the VPC. If traffic moves through an ALB, ECS or EC2 service, test health checks, redirects, uploaded files and PHP sessions before changing DNS. A successful deployment is not proof that the complete request path works.
Automation should cover more than a successful file transfer. Run deployment and smoke tests against a staging origin, then repeat product, login, discount-code, payment and checkout checks through CloudFront. My Raspberry Pi Runner guide shows how a small GitLab Runner cluster can provide repeatable build capacity; it is useful for rehearsals, not a production home for the storefront.
Securing DNS and measuring the cutover
Use Route 53 or the existing authoritative DNS provider to point the storefront hostname at the distribution. Lower the DNS TTL in advance, keep the old record available during validation, and use health checks or weighted records for a cautious rollout. Managed WAF rules, rate limits and bot controls should protect expensive PHP endpoints before traffic is opened.
Measure the business as well as the infrastructure. Compare cache-hit ratio, origin latency, 5xx rates, checkout completion and revenue per session before and after the move. CloudFront standard and real-time logs, ALB logs and application traces need a shared request identifier. Synthetic checks from Melbourne, Sydney and Brisbane make regional regressions visible before customers report them.
Watch the bill as well as the dashboard. Request charges, data transfer, invalidations, WAF capacity and origin compute all remain. Australian pricing usually needs one AUD display with GST included; if the store exposes other currencies or markets, include only the dimensions required to produce the correct page in the cache key. A fair dinkum speed gain is one that preserves margin.
Rehearsing migration with a practical checklist
Rehearse with a production-shaped catalogue and representative media, not a handful of placeholder products. Warm the cache with common category and product URLs, then apply a traffic profile that models Click Frenzy or a sale email burst. For a cautious release, create a second distribution and use weighted DNS records to send a small cohort through it while the current path remains available for rollback.
Plan cache invalidation for price changes, stock updates and campaign edits. Versioned asset filenames avoid many purges, while short TTLs limit the age of HTML that cannot be versioned. If product copy is managed through Microsoft 365, include that publishing path in the rehearsal. The SharePoint content guidance can help separate content operations from storefront delivery, while the commerce team defines which exported pages may be cached and how stale content gets removed.
During the busiest period, autoscaling, database headroom and an operations contact matter more than a perfect cache ratio. Put the person who can pause the rollout and the person who can restore routing in the same change brief. Test a CloudFront or origin failure under load, document who makes the call, and keep checkout monitoring visible throughout. A practical sequence keeps each change measurable and reversible:
- Record baseline page speed, origin load, checkout conversion, payment failures and support-contact volume.
- Label every route as shared-cacheable, private, signed or origin-only, then review those labels with developers.
- Automate builds, security checks and end-to-end tests before a distribution receives customer traffic.
- Shift a small DNS-weighted cohort, watch checkout and order data closely, and define the threshold that pauses promotion.
- Keep rollback DNS, origin capacity and a cache-purge runbook open until the busiest sales period has passed.
Start with a measured migration
Begin with the homepage, static assets and anonymous catalogue pages, then add selected product and category templates after observing real logs. Keep payment processing outside shared caching and use a canary distribution for the first traffic slice. Promote only when checkout success, order totals and support-contact volume remain normal.
Create a one-page migration brief this week: name the cacheable routes, nominate an Australian origin region, set measurable success thresholds and rehearse the rollback. Then launch the first distribution with a measured cohort, document every configuration change and expand traffic only while customer and operational metrics remain stable.
Karl Katzke