Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying wordpress as AWS lambda functions?

Tags:

I am wondering if it is feasible to deploy wordpress as a series of lambda functions on AWS API gateway. Any pointers on the feasibility/gotchas would be greatly appreciated!

Thanks in advance,

PKK

like image 574
PKK Avatar asked Apr 04 '16 01:04

PKK


People also ask

Can I host WordPress on AWS Lambda?

AWS Lambda + WordPress IntegrationsZapier lets you send info between AWS Lambda and WordPress automatically—no code required. automatically do this!

Can WordPress run serverless?

One type of application that has the most to gain from serverless PHP is WordPress. Serverless PHP eases the burden of scaling WordPress while offering the same performance benefits that you'd get with a top tier host.

Can you run PHP on AWS Lambda?

Creating a PHP Lambda functionYou can create a Lambda function via the AWS CLI, the AWS Serverless Application Model (SAM), or directly in the AWS Management Console. To do this using the console: Navigate to the Lambda section of the AWS Management Console and choose Create function.

Can a website be hosted on AWS Lambda?

They can serve your blog, or a landing page, or a simple company website with a few pages and a couple of forms for lead generation. Any sort of HTML/CSS/JS can be served by AWS Lambda or similar implementations of serverless functions. Lambda can also serve the other side of a website: the API.


2 Answers

Is it possible? Yes, anything is possible with enough time and effort. Is it worth it? That is a question best to ask yourself.

PHP can be run on Lambda as per the documentation located here: https://aws.amazon.com/blogs/compute/scripting-languages-for-aws-lambda-running-php-ruby-and-go/ .

The bigger initial problem as stated in other comments is a persistent file system. S3 for media storage is doable via Wordpress plugin (again from the comments) but any other persistent storage for the request / script execution is the initial biggest hurdle. Tackle one problem at a time till you get to the end!

like image 23
David J Eddy Avatar answered Oct 17 '22 08:10

David J Eddy


You'll have a lot of things to consider with persistence and even before that, Lambda doesn't support PHP. I'd probably look at Microsoft Azure Functions instead that do support PHP and do have persistent storage.

While other languages (such as Go, Rust, Swift etc.) can be "wrapped" to run in AWS Lambda with relative ease, compiling PHP targeting the same platform and running it is a bit different (and certainly more painstaking). Think about all the various PHP modules you'd need for starters. Moreover, I can't imagine performance will be as good as something like a Go binary.

If you can do something clever with the Phalcon framework and come up with an easy build and deploy process, then maayyyybee.

Though, you'd probably need to really overhaul something like WordPress which was not designed for this at all. It still uses some pretty old conventions due to the age of the project and while that is all well and good for your typical PHP server, it's a different ball game in the sense of this "portable" PHP installation.

Keep in mind that PHP sessions are relied upon as well and so you're going to need to move those elsewhere due to the lack of persistence with AWS Lambda. You can probably find some sort of plugin for WordPress that works with Redis?? I have to imagine something like that has been built by now... But there will be many complications.

I would seriously consider using Azure Functions to begin with OR using Docker and forgoing the pricing model that cloud functions offers. You can still find some pretty cheap and scalable hosting out there.

What I've done previously was use AWS ECS (Docker) with EFS (network storage) for persistence and RDS for the database. While this doesn't carry the same pricing model as Lambda, it is still cost efficient. You can set up your ECS Service to autoscale up and down. So that way you're running the bare minimum until you need more.

I've written a more in depth article about it here: https://serifandsemaphore.io/how-to-host-wordpress-like-a-boss-b5993fcfbd8e#.n6fbnf8ii ... but it's basically just the idea of running WordPress in Docker and using EFS to offload the persistent storage issues. You can swap many of the pieces of the puzzle out if you like. Use a database hosted in some other Docker service or Compose or where ever. That part need not be RDS for example. Even your storage could be handled in a different way, though EFS worked pretty well! The only major thing to note about EFS is the write speed. Most WordPress sites are read heavy though. Your mileage will vary depending on your needs.

like image 136
Tom Avatar answered Oct 17 '22 07:10

Tom