statement:
This article is transferred from the DEV Community website, and the article translation is provided by the developer community;
Click the link below to view the original English text:

You might think this article is headline-grabbing, but it's not. I've built a fully functional static serverless Wordpress solution on Amazon Cloud with a global CDN, WAF and Class A SSL for just 1 cent per day. It's fast, resilient, scalable, and, unlike many Wordpress sites, is not vulnerable to brute force login attacks.

Know that you can do this too. It's in an open source Terraform module, and I hope this easy access will turn the internet upside down. Set up from scratch in 30 minutes.

What is Static Serverless Wordpress?

Static Serverless Wordpress is a Community Terraform module from TechToSpeech that requires only a registered domain name with DNS pointing to Amazon Cloud Technologies.

It creates a complete infrastructure framework and starts a temporary Wordpress container. Like any other Wordpress website, you can log in, customize it, and finally publish it as a static website, relying on a global CloudFront CDN and S3 Origin. Once done, you can close the Wordpress container for almost no cost.

The point is that minimal configuration is required, as most of the resources you need are pre-installed and pre-configured based on industry best practices and efficient running costs.

Do you have a website you want to convert to static serverless Wordpress? no problem.

There's a lot to cover here, so it's split into two different articles: the short and the long . If you want to take the time to get started right away, please read the first article; if you want to understand the specific operation mechanism of the solution, please see the second article.

If you're familiar with Amazon cloud technology, you'll figure it out in no time. However, even if you're new to it, the steps in the short version will help you get up and running quickly.

image.png

short version

In the following steps, we will use the example domain www.peter.cloud .

Step 0 - Create an Amazon Cloud Tech account .

Step 1 - Domain

In your Amazon Cloud Technology account, create a Route53 hosted zone for the domain name. Once created, it will display four DNS name servers for your new website.

Enter the domain name registration address (which can be Amazon Cloud Technology itself, or another address), and update the DNS server to the four you just created.

Step 2 - Tools and Credentials

Make sure you have Terraform , Amazon-CLI (user and credentials) and (optional but preferably) Docker enabled for the service.

Step 3 - Code and Planning

Check out the project's GitHub README for rich code examples for quick setup and deployment.

The module does pretty much everything on its own, but here are some additional specific resources that make it a completely hands-free end-to-end process. Docker needs to be installed, and the Amazon CLI's default region and configuration file are properly configured.

Terraform initializes, plans, applies, then sits down for a cup of tea. The complete end-to-end creation process should take around 10 minutes. Unless you do something wrong, no errors will occur in the process. However, just in case, go through the planning and application steps one more time.

Step 4 - Start Wordpress
Everything you need to create to start Wordpress and publish a static website is done in step 3. But so far it has not started. If you didn't add the optional Terraform resource to trigger the CodeBuild job, you need to go to the CodeBuild console of your chosen region, start the "-serverless-wordpress-docker-build" job and wait for it to finish (takes about 2 minutes).

Change the module's startup "properties" from 0 to 1, and run "terraform apply" again. Wordpress will now start. First-time setup takes about 5 minutes, including initial website creation, configuration, and installation of necessary plugins.

By default, your Wordpress installation will be at http://wordpress.yourdomain.com (why no SSL? See the long version for details).

The default username is "supervisor" and the default password is "techtospeech.com". You can modify the username, password, and default subdomain in the module configuration, or you can modify it after logging in to Wordpress. Make sure to do so.

Step 5 - Publish

Now, Wordpress is installed like any other Wordpress. You can install most plugins (though none with server-side functionality will work in a static website), any theme you like, and even import a backup of your current website. SEO plugins like Yoast also work fine. If the website is idle for more than 5 minutes, the backend database will be paused (to save money), but just refresh the admin console and it will start again after a delay of a few seconds.

When you want to stop the container, toggle the "startup" property of the Terraform configuration back to 0, then rerun the "terraform app". You can also manually change the ECS service to 0 tasks in the Amazon Cloud Console. In the future there will be better ways to start or pause a website with one click. Stopping the container won't lose any data - the database will be saved in the background along with any files, images, plugins or themes you have installed. Its state is preserved until the next boot.

However, it is crucial to remember to close the container . Otherwise it will keep running - and even then, it won't incur much cost, but the point of this solution is to save money, not waste it (another future update is the auto-shutdown feature when idle).

When everything is ready, it's time to publish. Check out the WP2Static plugin and the WP2Static S3 plugin that have been automatically installed. Leon Stafford is the creator of these plugins. He is the open source static WordPress guru, without him, there would be no deployment mechanism for this project. Read more about Leon in the long version.

You can see all the WP2Static options, you can tweak the configuration deployment, but the automatic setup is pre-filled with what you want to publish. Click the "Generate Static Site" button, then periodically refresh the log to check the status. This action grabs each URL and rewrites it to a compact static version, which is then pushed directly to an S3 bucket that supports the static version of the website.

This process takes 3-5 minutes, or longer if your site is larger. We're working on a faster way ( help welcome! ), but the version bundled with this setup is currently stable and reliable, just needs a little patience.

Once the process is over, you're done! Head over to the https version of the website ( https://www.peter.cloud in this example) and you'll be surprised how the website looks the same as before, only now it's serverless , static, cached by the global CDN, won't crash due to some weak DDoS attack or wp-login brute force attack. Try going to https://www.peter.cloud/wp-admin . Ha, the website doesn't exist at all!

Is it really only $0.01 a day?

Yes, but not quite. It depends on the situation.

Take a look at a typical use case. Let's say you're a dull techie with a personal blog site (that's me, mine is petewilcock.com ), you publish a few articles, and you get 50 to 200 hits a day. With this traffic, the website runs statically without any intervention and costs about $0.01 per day, which is perfectly legal.

On the other hand, let’s say you own a large, globally-renowned content-generating business that publishes thousands of articles a month and has millions of hits… that’s a lot more. The only variable cost in terms of traffic is the CloudFront distribution fee, and you can take advantage of the CloudFront Security Savings Bundle to get discounts to reduce costs. If your business is particularly large, you can ask Amazon Cloud directly about the price of custom CloudFront. WAFs have some unavoidable fixed costs that add at least $0.60 per day to running costs. But if you're not in a firm position and need a WAF, then I guess you can afford it.

I run several static Wordpress sites with this setup, and a $1 monthly Savings Bundle covers a lot of usage. Previously, I was running a T3 web hosting server with a CPanel license, which cost about $600 per year. For some reason, such a comparison isn't strictly fair (e.g. the setup doesn't currently handle email, but be warned, it will be updated in the future!), but you start to see how this is "traditional" with the basic website The difference between managed settings. Even other vendors of "static" Wordpress sites can't compete because they need profit and you don't.

The only other costs to be aware of are the cost of running the ECS Fargate container for Wordpress (it runs in Spot mode, so it's very cheap), and the RDS Aurora Serverless v1 database for the Wordpress database. This is actually the most expensive part (you guessed it, a cheaper version will be offered in the future if you want to sacrifice functionality and convenience), but only charges when you actively modify the site. For example, if I spend a few hours editing the site, it might cost about $0.30. Best of all, in the vast majority of cases, if you don't add content, it costs almost nothing.

problem solved

No setup is ever going to be perfect, so if you have any issues with Terraform modules, please report them on our GitHub and we'll take a look. We also welcome your contributions.

If you're having trouble using the WP2Static plugin, check out their issues page for common issues and solutions, and any issues you encounter may be resolved the way you want. You can always upgrade the plugin or Wordpress - but be sure to back it up first. I recommend UpdraftPlus , an excellent free Wordpress backup plugin.

Summarize

First, let me remind you again. Don't forget to close your Wordpress container when you're done.

This module is the result of several months of painstaking iterations, both for my own use and broad applicability so that I don't embarrass myself after a public release. It brings together all my experience with Amazon Cloud Technologies since I started in 2014 and condenses every element of DevOps and web development I have mastered into a compact solution that anyone can use. I hope it helps you.

Article by Pete Wilcock
Pete Wilcock for AWS Community Builders


亚马逊云开发者
2.9k 声望9.6k 粉丝

亚马逊云开发者社区是面向开发者交流与互动的平台。在这里,你可以分享和获取有关云计算、人工智能、IoT、区块链等相关技术和前沿知识,也可以与同行或爱好者们交流探讨,共同成长。