How to host PHP websites on the AWS cloud - comparing the major options

Idealstack • June 18, 2018

configuration

All the ways to host PHP websites and Apps on the Amazon AWS Cloud - compared

PHP is one of the most popular languages for building websites and web applications.  It’s fast and easy, there’s a thriving community of developers, and it has an excellent base of applications and frameworks like Wordpress and Laravel to work with.  All this usually means PHP is the quickest and most affordable way to build a website or web app.

Unfortunately the world of PHP hosting remains remarkably backward.  Many PHP sites and apps are still hosted on a single server with no fault tolerance or scalability.  The cloud revolution that has completely changed the face of most other parts of IT has largely passed PHP by.

Why is that? Well it’s been pretty hard to get a PHP app working well on a scalable cloud cluster.  This has often driven people to use other languages such as Python, Ruby on rails or Nodejs to build the kind of apps that need scalability and reliability. In fact many people think PHP can’t be used to build these kinds of apps! (which is nonsense).  But it needn’t be this way, and there’s a number of ways to get a PHP site up and running on AWS

Get a single EC2 instance and run Linux on it

One option is to setup an EC2 instance, which essentially just provides a virtual machine.  You can of course treat this like any other server, for instance by installing a LAMP stack on it and running PHP sites, or even installing a hosting console like Plesk or CPanel to make setup and maintenance a bit easier.

The downside to this is that you're not really any better off than running your own server.  You don’t have to worry about hardware anymore, but you’ve still got a little server for which you have to manage OS updates, security and more.  It’s really not worth doing this.

Elastic Beanstalk

Probably a better option for many is to use Elastic Beanstalk.  EB simplifies the task of creating a ‘proper’ stack on AWS. In Elastic Beanstalk you upload your app and choose a platform (eg PHP) and EB will do the rest.

The big benefit of this is that what Elastic Beanstalk builds is a ‘well architected’ cloud platform.  It’s not just some simulating some kind of retro solution from the past like a single EC2 instance. You can enable ‘Managed Updates’ which provide operating system updates without you needing to manage these, which is a big win for security and easy of maintenance.

Probably the biggest con is that EB doesn’t do shared hosting.  Each “App” needs its own complete cluster of multiple instances and other services in order to provide a scalable and reliable platform.  This means it’s not cost effective for hosting websites (apart from extremely large ones) as it will cost hundreds of dollars per month.

The other is that it only works well with modern apps custom built for cloud environments : eg not wordpress, drupal etc.  Unless your app is designed to work with AWS, eg using S3 for file storage, database shared sessions etc, it’s not going to work without a lot of extra tweaking.  One can’t simply upload wordpress to EB and expect it to work.

Your developers will need to change their workflow to use EB.  You need to upload your app as a ‘bundle’, and you can’t access the live environment to make direct code changes.

What all of this means is that EB isn’t a good option for hosting and developing websites. It might be a good option for apps (eg if you’re a startup building the next Uber or Netflix).

Build your own scalable hosting cluster

This option is pursued by many startups, and it makes sense if you have a lot of sophisticated devops developers, a lot of funding and you know you’re in it for the long term.  

If you go down this route, I recommend you take a look at Cloudformation or possibly Terraform  as a way to create ‘infrastructure as code’.  Clicking around and manually creating things in the AWS web console is a great to learn how things work ‘under the hood’, but it’s not a practical way to run an infrastructure and in many cases the time you spent learning in the GUI would be better spent learning Terraform or CloudFormation.

The biggest downside to this is that it takes a very long time.  Learning all the necessary tools and putting them together will probably take between six months and a year, plus then a period of several years of enhancing your stack and working around problems as you discover them.  After many years you will hopefully have the sort of stack that you hear about Google, Facebook or Netflix having, but the years of instability, learning and pain along the way has an incalculable cost.

Lightsail

Lightsail is a relatively new AWS service that provides a VPS (Virtual Private Server), similar to those provided by the likes of Digital Ocean, Vultr or many other providers.

Pricing is pretty cheap, starting at $5 USD per month (although realistically expect to pay $10 USD for something production-ready), and setup is pretty simple too.  Lightsail comes closest in the AWS cloud to a service built for PHP developers

One problem lightsail solves is providing secure affordable hosting.  By giving each of your sites a seperate lightsail instance they are isolated from each other.

Lightsail isn’t ‘real AWS’ - it doesn’t really provide any scalability or fault tolerance.  Lightsail provides a simple load balancer - so if you create multiple Lightsail VPS’s, install your app on all of them, and work out how to make it operate on a cluster you can distribute traffic over lightsail instances. This of course increases the cost of hosting your app considerably, but you still have to do much the same work as building your own cluster to really make this work. We wouldn’t recomend this approach if you truly wanted to make a fault-tolerant scalable architecture for an app .

Similar to installing an EC2 instance, a VPS is essentially a little server that needs you to manage it’s security, particularly by installing updates to it’s underlying OS on a regular basis.  That of course is relatively simple provided you know linux, but these machines are not zero-maintenance.

Other third party solutions that ‘use AWS’

There’s a few providers out there that claim to help you setup your app on AWS, but they don’t work on your AWS account - they may allow you to select an AWS instance and region but they’re essentially reselling instances out of their own AWS account.  We won’t name names here, beyond saying that we think this solution is pretty crappy.  You aren't really setting up sites on AWS unless you have access to your own AWS account

Often these providers can match AWS’s on-demand pricing - by buying reserved instances on AWS you can reduce costs by 70% and then reselling them to you provides a good markup for them.  Of course you should have the opportunity to signup reserved instances yourself and pocket those savings.

These solutions are not ‘really AWS’ unless you can plug in all the other AWS services - eg CloudFront for CDN, Elasticache for caching, services like SQS and SNS for batching and queueing, S3 for affordable enterprise storage.  They often don’t even provide any HA or autoscale.

Idealstack

Of course we’re biased, but we think Idealstack is the best way to run PHP on AWS.  Of course we do, that’s why we built it!

There’s a number of key reasons for this - some of the other ways of running PHP on AWS can achieve one or two of them, Idealstack is the only system that can do them all:

You own your hosting

Idealstack sets up a stack on your own AWS account, and you own that stack.  Even if you later choose to cancel Idealstack your stack will keep running (although of course you lose access to benefits we provide like automatic updates, and our management interface)

Developers should focus on building sites, not Devops

The first thing that Idealstack does is provide a ‘normal’ PHP environment.  What we mean by that is Idealstack provides the things PHP developers expect:

  • Upload files over SFTP

  • SSH to your site and run commands

  • GUI for database management and access

You developers can work with Idealstack just like they do with any other hosting environment, they don’t need to be retrained.  This is great especially when your hiring or dealing with external teams. 

Setting up the hosting cluster is also very easy and usually takes about 30 minutes, 20 of which you can spend making a cup of tea while the Idealstack system automates everything for you.

Idealstack takes away most of the hassles of server management.  In Idealstack servers (ie EC2 Instances) are ‘cattle not pets’. If they misbehave they are automatically replaced.  OS updates are applied automatically by destroying the instance and creating a new one. You can scale them up or down, add new ones manually or automatically, without ever really having to think about them.

Runs any PHP app

Idealstack runs any app like Wordpress, Drupal, Joomla, frameworks like Laravel or CodeIgniter, or your own legacy code on a scalable fault-tolerant cluster, but without you having to modify the app.  How do we do this?

  • Shared storage by default - using AWS’s EFS shared filesystem, code and fiels are shared across the cluster, so apps that locally write files (which is pretty much all apps) work

  • Shared sessions by default - Idealstack sets up a DynamoDB table and session handler that writes to this for each site.  This solves one of the biggest challenges of scaling PHP across a cluster - by default PHP sessions are written to files on local disk

Secure shared hosting

In the web industry - we’re often dealing with multiple clients and we want to host their websites affordably.  What that often means though is that we make their hosting a bit crappy.

One of the great things about Idealstack is we can flip that equation on it’s head - by providing shared hosting, we can make their hosting great.  The reason is that by combining together a lot of clients you can achieve economies of scale that mean you can have a fault-tolerant autoscaling cluster that all these sites run across.  This means you can provide a well-architected high-end hosting environment for a very small cost (as little as $5/site)

To achieve this Idealstack runs each site inside a container across a well-architected cluster.  Idealstack uses Docker (with an image we manage) and ECS to do this, but you never really have to worry about it, it happens ‘under the hood’

Well-architected, stable secure hosting

Unlike most of the other ways of hosting sites on AWS, Idealstack is designed from the ground up exclusively for the AWS platform and it does things ‘the right way’.  What we mean by that is that Idealstack runs a cluster across multiple availability zones in AWS, and provides autoscaling to deal with load spikes (load spikes are the number 1 reason PHP websites experience outages).

AWS services are used automatically where possible - for instance ACM is used for registering SSL certificates, SES for sending email, ALB for load balancing, EFS for storage, RDS for database servers, ECS for managing clusters. You can plug in other AWS services like CloudFront for CDN, Elasticache for caching, SQS for queuing, S3 for mass storage and so forth.

Conclusion

So obviously we think Idealstack is the ideal stack for hosting PHP on AWS. Of course, you say, they're biased! They would say that!  But that's why we built it and what gets us out of bed every morning to work on it.  We think you should give it a try : there's a free trial that you can combine with the AWS free tier to give you a no-risk way of seeing if you agree with our assesment here.  Give it a go!

Harness the power of AWS for hosting PHP-based websites and apps.


Idealstack is a powerful hosting console that creates a modern,  autoscaling, best-practice, AWS-native hosting cluster for PHP-based code in your AWS account

 

How it works     TRY IT Now For Free