WordPress hosting for cheap perfectionists
Many WordPress websites could be replaced by static HTML. Static websites are cheaper, faster, and more secure to host. Why not use WordPress as a static website generator so we can still edit content via our web browser and use many of the great WordPress themes and plugins?
ServerlessWP enables hosting the backend WordPress installation, where we add and manage content, on AWS Serverless products so that we don't have to worry about maintaining a server. Serverless means we only pay for what we use, and most websites don't get edited too often. Combined with AWS free tier offerings, we can host the backend for next to nothing in cost.
ServerlessWP puts Basic Authentication in front of the backend WordPress installation to limit its exposure to bots and other sources of unwanted traffic.
The backend WordPress website is crawled to generate the static website. The static HTML is uploaded to Amazon S3 for storage and hosting. AWS CloudFront is used to provide CDN hosting and SSL for the public-facing website.
Disclaimer: This is a proof of concept!
- Install the Serverless Framework for AWS - Serverless installation guide
- Clone or download this repository
- Place necessary binary files in the "bin" directory.
- "php-cgi" and "wget" are the currently necessary binaries. They must be compiled to run in the Lambda environment.
- This can be handled by running the "./build_bin.sh" script if you have Docker installed.
- The "./bin/lib" directory requires a library noted in bin/lib/readme.txt. It will be put in place if "./build_bin.sh" is used.
- Place a WordPress installation directly in the "wp" directory so that "index.php" is found in the root of "wp".
- This can be handled by executing the "./build_wp.sh" script.
- Modify "wp-config.php" for ServerlessWP friendly configuration.
- This is handled by the "./build_wp.sh" script if used.
- Otherwise, use this wp-config-base.php as a guide.
- To handle file uploads in the WordPress backend, install the necessary WordPress plugins (also handled by the "./build_wp.sh" script):
- Place any other WordPress themes or plugins in the respective wp-content directories like a standard WordPress installation.
- Edit serverless.yml
- The "custom" section at the top of the file has variables that should be reviewed.
- Run "npm init"
- Run "severless deploy"
- The initial time this is run, it may take 30-60 minutes for AWS to create the necessary resources.
- Mitch MacKenzie - mitchmac
The following articles and repositories provided ideas, examples, and best practices for various parts of the project:
- Chris White - Hosting a Laravel application on AWS Lambda
- Danny Linden - aws-lambda-php
- Peter Tilsen - basicAuthApiGateway
- hemanth.hm - Copying shared library dependencies
- Ivan Perevernykhata - Start/Stop RDS instances on schedule
This project is licensed under the MIT License - see the LICENSE file for details.