I’m a big fan of WP Engine and I prefer to use managed hosting for sites that I consider mission-critical. However, I’ve always entertained the idea of running a web server from my home network, but there are two main reasons why I haven’t. First, I don’t want to expose and associate my home’s IP with the site. And second, I have a consumer internet plan – albeit fast – that’s not designed for web hosting.
When Cloudflare launched its Automatic Platform Optimization (APO) service for WordPress, a core feature was its ability to host a near-static version of the site using service workers. That got me thinking about how well it might work for a self-hosted site on my home network. I decided to set it up, and I was pleasantly surprised by the results and the cost.
Table of contents
How to self-host WordPress on a home network using APO
You will need a dedicated computer that’s always online. For me, that’s a headless Mac mini that I manage via Remote Desktop. Ideally, the computer shouldn’t be used for anything other than hosting and perhaps as a media and file server. I also recommend doing a clean install of the operating system.
Setting up the hosting environment
The next step is to add a hosting environment to the computer. The easiest way is to use MAMP Pro. MAMP Pro is an app that works on Mac or Windows and has everything you need to host a WordPress site.
The more complicated way is to install Apache, PHP, and a MySQL-compatible database manually. The advantage to that is everything runs in the background as a service and is typically more stable.
I chose to do it in a more complicated way. Fortunately, Andy Miller published excellent instructions on installing Apache and PHP on macOS Big Sur and how to install MariaDB, a MySQL compatible database. (Sorry Windows users. The instructions are only for macOS, but I’m sure there are good instructions for Windows out there too.)
The final step is to download and install WordPress. It got a little tricky for me because I initially installed it for
http://localhost and then changed it to the domain name I was using after completing the Cloudflare setup. I was able to access the site, but I wasn’t able to access the Admin anymore. I eventually fixed it by simply changing the site to the non-secure (
http) version of my domain name. Adding
https caused a redirection loop because of how Cloudflare works. And even though the WordPress settings have
http, it will still use
https in the browser when you access it.
Configuring the modem and router
This is the part where you might have the most difficulty. Everyone has different equipment and connection types, but you must do some fundamental things to make the site publicly accessible.
IP Passthrough and NAT/Gaming
If you use a router behind the ISP’s modem, as I do with the AmpliFi Alien, you must enable Passthrough from the modem to the router. That passes the public IP address to the router. If you use the ISP’s modem and router that came with the service, you shouldn’t have to worry about enabling Passthrough.
You may also need to add NAT/Gaming entries on the modem. I added entries for port 80 and 443 to allow HTTP and HTTPS traffic.
The computer will need a static lease from the DHCP server on your router. This will make it so the IP address never changes, which is important for port forwarding.
The last requirement for the router is to set up port forwarding. This will forward all public traffic using port 80 and 443 to the computer used as a server. The IP address should be the same IP used for the static lease.
Add the domain to Cloudflare if it hasn’t already been added, and choose the Free plan. Then add an A Record with the public IP for your home internet.
Most home internet services don’t use static IPs, but they also rarely change. However, if your IP changes often or you’re worried about it changing, you can set up a dynamic DNS service that will monitor and change the IP on Cloudflare automatically. Cloudflare has details on how to set it up, and they recommend using DNS-O-Matic. Also, if you’re using MAMP Pro, then you’re in luck. DNS-O-Matic is built into the app.
Next, you need to install and activate the Cloudflare plugin and configure APO on Cloudflare. Follow the instructions in this Coywolf News article to do that.
After that, if you’ve done everything correctly, you’ll be able to access your site using the domain you set up.
The benefits of self-hosting with Cloudflare’s APO
Cloudflare’s APO not only performed well, but it also addressed the issues I mentioned at the beginning of the article. These are the benefits I discovered from using it.
- Fast – The service workers do most of the work, and delivering the site doesn’t rely heavily on my home connection or server. Testing it on web.dev resulted in a score that was comparable to hosting on WP Engine.
- High availability – When I ran a stress test on Loader, it performed extremely well. It was able to handle thousands of visitors per second without any noticeable impact.
- Private – Cloudflare uses a different IP address for the A Record than the one I saved. It acts as a DNS proxy and uses IP addresses from its Edge servers. That means if someone does a DNS lookup, the IP address for the A Record will be different from my home IP.
- Cheap – It costs $5/mo to use APO with WordPress. That’s it. You get speed, high availability, privacy, and the ability to manage the site at home for only $5/mo.