Wordpress on AWS: smooth and pain free
cloudonaut.io
cloudonaut.io
The first step is building your WordPress site correctly, and for me, that starts with using trellis (https://roots.io/trellis) and bedrock (https://roots.io/bedrock).
He's partially correct about S3 for media and uploads, but you want to take it one step further and use Imgix for actual image (jpeg/png) delivery because it'll do all of the transformations, cropping, etc. for you without WordPress mucking it up. At that point you have a fairly stateless WordPress installation and can spin up any number of instances of it. Here's my plugin for handling both S3 and Imgix: https://github.com/jawngee/ilab-media-tools/
CloudFlare is really the best thing to happen to WordPress since Imgix. Using CloudFlare's ability to cache at the root and sending correct caching headers from WordPress to CloudFlare, you are virtually indestructible.
We run a news site that gets about 500K uniques a month off a $20 instance on Digital Ocean this way. Granted, it's static, eg no user directed dynamic content like comments, votes, etc.
We build a lot of WordPress sites this way.
[0]: https://github.com/automattic/batcache [1]: https://github.com/tollmanz/wordpress-pecl-memcached-object-...
I do wonder how much energy is wasted from poorly optimised websites & systems?
http://www.slashgeek.net/cloudflare-making-internet-little-b...
Well that's a funny opener.
TL;DR: rather than configure your uploads to go to S3, one of AWS's most battle hardened and time tested offerings, use a service that was launched 10 months ago and can definitely scale perfectly and will never have any issues. Then you can even keep on managing your htaccess files using a WordPress plugin and skip that pesky version control!
Using S3 for the uploads solves our problems without needing EFS, as we disable file system changes through other methods. Plugin installs or upgrades are great, but aren't tracked in the git repo, so we do those via local upgrades and deploy out to AWS instead.
The article also mentions installing WordPress as being a pain, but you can easily automate this using wp-cli [3] if you want to. Your RDS containing the WP data is going to be shared though, so there's no real need to install more than once.
[1]: https://github.com/humanmade/aws-ses-wp-mail [2]: https://github.com/humanmade/node-tachyon [3]: http://wp-cli.org/
[0] See "Amazon S3 Data Consistency Model" on this page: http://docs.aws.amazon.com/AmazonS3/latest/dev/Introduction....
It's not a bad idea. Who said that?
Put your blog behind cloudflare. It will cache most of the requests and save a lot of load and bandwidth on your instances.
The persistent and shared EFS volume was the missing piece for running WordPress without frustrating patches.
And CloudFormation is the AWS best practice.
Convox has a few serious WordPress installs. The only difference is that it uses ECS so those EC2 instances can be utilized for more apps.
Also you can hack on the WordPress site locally with Docker via 'convox start'
https://convox.com/docs/wordpress/
Disclaimer: I work on Convox.
Latency on stat() - PHP is often a oop-monster these days with thousands of fs reads as it loads the code? (there are certainly ways to dodge that overhead though).
Have you seen the filesystem stall for any reason? Any caveats with concurrent writers (such as cache/ directories or generated images with deterministic paths etc).
You say without frustrating patches - are there any general limitations with using EFS?
Have you used self-managed NFS for the same purpose before? Any comparison with EFS?
This was on a workload much tougher than WordPress.
I haven't run my own NFS for comparison.
I recommend reading the NFS v4 spec. AWS has all the pieces to implement the protocol as well as anyone can.
This allows you to sidestep a large amount of pain points with shared filesystems, and every ec2 server has local disk performance.
There should be easier way, e.g. in Azure you can start WordPress (includes MySQL, limited to one app service instance) with one click, not sure what are the costs of maintaining that, but at least starting one in that case is pain free.
Sure you can click to set up WordPress on other hosts.
But how do you scale capacity of the servers or the database? How do you peer the network to your other cloud resources? How do you mirror the stack in another region?
With CloudFormation resource management is a few API calls away.
You can also use CloudFormation in point and click mode to create a stack and update its resources.
It may be overkill for some cases but for serious systems it's the best practice.
Maybe that is from having been through the ad-hoc or "well, its easy to spin up, but this only works for a single node" setup roundabout a few times.
True, although ongoing maintenance of a CloudFormation template isn't significant. It's essentially a specification of the state of the infrastructure, which AWS is then responsible for making come true. It's also their stuff from CloudFormation back, so they're on the hook for making sure nothing changes that would break it (relative to Terraform or other alternatives).
Also keep in mind that AWS services are usually encapsulated from each other, which is a good thing. The result, though, is that defining something like this involves a lot of parts. You need to define its private network, its subnet masks, its EC2 instance types, its database type and configuration, etc. The author also took it a step further to define CloudWatch alarms and scaling policies, which is great.
It is something that requires understanding if changes are necessary, but it's not something that you would expect to need tweaks over time.
> There should be easier way
There is--he could have started Wordpress by just launching an instance with userdata that installs it and sets it up. This isn't really comparable to that because it involves multiple servers behind a load balancer, a CDN, a hosted DNS zone, a separate relational database service instance, and autoscaling.
Has anybody working towards serverless version of wp?
You can easily manage to get this setup at 30$/mo with Scaleway for example.
So you're looking at ~ $50/mo.
For a setup that can now scale to any volume independently on the HTTP, compute and database tiers.
Overkill for a personal WordPress. Just right for a serious business.
I'm curious on what a "serverless version of wordpress" consists of, please enlighten us on the technical details of a serverless wordpress, sincerely. And how would you have a "serverless shopping card" too ? I'm really curious about the how it. If you're talking about a static blog generator then it already exists (Hugo,...) is this what you call serverless ?
I built a service [1] for this latter part (authentication, CORS sql database, and static file hosting). The pieces one could use to build anything for a statically generated site. Adoption has been... non existent up to now.
It would provide unlimited and automatic scaling, simplified setup/architecture and we would pay only for what we use.
Not infeasible to think you could use Lambda to generate a static cache of a WP site onto S3 and update files on demand.
(I know this reads like an ad. I'm not affiliated with pantheon except as a user. Pantheon comes close to making wordpress not suck.)
The first page of HN can send 10k users to a blog in about one hour. (don't know the peak rate per second).
RDS is here because keeping your database on the same server as your web server is not ideal at scale.
EFS is here because at some point you want to scale horizontally and it's one method to share underlying code (and perhaps cache).
ELB is here because if you have more than one web server, you need a load balancer
And as you scale, you could add services. This guide isn't for anyone who can host a tiny site on a tiny instance. You'd do that in AWS the same way you would with Digital Ocean.
Its _only_ running 2 PHP instances + 2 RDS instances + EBS storage costs + S3 buckets fees + ELB fees + CloudFront fees + traffic costs.
The smallest production instance on AWS is about $100 a month (c4.large) for 1 core (+intel HT) + 4GB ram + a few GB of EBS volume.
The setup requires at least 4 hosts, thus that's a start price of $400 a month + the other fees (hardly 10% more :D).
It's f* insane to pay more than $400 per month to run a blog. No matter the traffic.
>It's f* insane to pay more than $400 per month to run a blog. No matter the traffic.
It's insane if your site isn't being monetized at all and downtime doesn't cost you anything. What you spend on infrastructure should be a formula of risk vs. reward taking into account availability vs. lost revenue for downtime or visitor bounce due to errors, speed, etc. Site owners will happily pay whatever the cost is as long as they are not losing sales and their net income is positive.Not to mention that guys who can do that kind of custom setup are going for $150-300k a year nowadays. And it's gonna take man*months of work and maintenance.
They are cheap, overrallocated, burstable instances with a low quota of CPU usage (about 10% for a t2.micro). They can burst over the quota for short period of time and they can be interrupted for short period of time.
In short, the instance can pause anytime and stop processing traffic.
Try running a production database on that see where it gets you ;)
There are plenty of production workloads that are burst based in nature, and for those, t2's make plenty of sense. The micro is also hardly the only instance in the family - if you go to the opposite end, the t2.large has a baseline of 60%.
They also are not interrupted or paused, so I don't know where you're getting that. If you run out of credits your performance is throttled to baseline gradually over 15 minutes.
t2s are fine for production if you understand their strengths - workloads with low levels of constant usage and periodic bursts of higher resource utilization.
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/t2-instan...
The only issue is getting the plugins to auto update on all of the servers, which I am fairly certain you can do with Chef or WordPress just handles it.
I've gone the WP a number of times and it's been more headaches then it's worth. Everything seems like a hack on a hack. There are things like sage/roots that make it a "little" better.
My experience with WP has been the same. Seems like you get a basic theme installed, and then whatever functionality you need you just download, install and configure a dozen or so plugins. Can't find a plugin that you need? Oh, then you can just write a plugin that you download, install and configure on your own.
The bloat from that approach just drives me nuts.
We are on AWS and have a pretty sophisticated Chef setup, but I want to stress that if you are a SaaS company, you do _not_ want your Wordpress install as part of your production network. By running Wordpress yourself you're taking on upgrade responsibilities, and you need to be pretty diligent in upgrading in order to avoid exploits. At minimum you should put Wordpress in its own VPC; we ended up running on Heroku instead to keep it as far as possible from our production infrastructure.
If I were setting up a new wordpress blog for a company I'd go with WPEngine if possible, if not I'd host on Heroku, and only if it needed to scale a lot would I consider hosting it myself on AWS.
It's trickier when there is content on a page that has to be dynamically generated fresh (or nearly fresh) per page load. Most blogs never get into this territory (or have no reason to, at least) and most of us have experience with WordPress at the "look y'all, ima start a blog" level of sophistication, so there's this kneejerk toward feeling like this is total overkill.
But it's not if you have the problems that owners of complex, interactive, heavily-trafficked WordPress sites have.
Why use CloudFlare?
<3 for captchas. Maybe?The common argument is pricing, many people seem to prefer a relatively reliable monthly amount (that in the beginning might even be zero) to CloudFront's potentially expensive traffic costs.
I'm looking for a solution for my agency to put sites onto hosted instances like AWS or Azure, but my hesitance is that they aren't managed solutions and I'm afraid of getting hacked. Does anyone have any insight on how secure these solutions can be? My Azure instance has been running for years without problems, but that's my gamble with my one site and not hundreds of customer sites. I use CloudFlare's page rules to add extra security and caching and have WordFence just in case.
I'd love some insight into how I could scale a solution like this to be hundreds of sites on cloud instances while maintaining security. Perhaps they should all be separate? Would my personal solution be good for my company's clients? Managed solutions like WPEngine are just outrageously expensive for some of the sites we have that only get a handful of traffic (Azure offers Wordpress on Azure websites.)
If you wanna be extra safe you can have each site on its own vps. Although what's nice about keeping a bunch on 1 big vps is that you get to save a lot of time managing it as it can take a while to propagate changes across many VPS and if they all have different setups it can get confusing.
To do 1 site per vps properly, you should have fleet management going like Ansible or Puppet so that you can maintain them all easily. That way all the code is hosted on a build server, and individual environments get built for each site.
What I do is use redundant RDS, ELB etc but on all the WP installs have an inhouse plugin that with any change it ioniced rsyncs that vhosts tree to all webservers and ssh's a command to them all to dump their WP cache.
It may seem hackish but the sites absolutely fly, have tried several clustered file systems but all that complexity hits reliability and speed.
And if your cache is all on disk, a very quick win would involve moving that to memcache, no? That also makes forced expiration very easy.
Of course there are managed services for all of these things anyway.
ee site create mysite.com --wpfc --php7 # install wordpress + nginx fastcgi_cache, with php7
ee site create mysite.com --wpredis --php7 # install wordpress + nginx redis_cache with php7
I have yet to see a site of mine, which breaks my limits on a 5$/month droplet.
[1] https://roots.io
The database, Wordpress, the file storage. Entirely self contained.
I occasionally persist the AMI so I can spin up a new updated system base, and have regular backups of the files and database. My monthly cost is ~$9 on AWS. I've had literally minutes of downtime over the past several years.
Obviously this guide is geared to a more serious installation, but there is the danger that the more reliable a system becomes, often the less reliable it becomes. EFS and NLB configuration changes or problems taking the system offline, for instance.
https://codex.wordpress.org/Function_Reference/capital_P_dan...