WP-Cron, BackWPUp, and Apache Virtual Hosts

We were forced to switch hosts recently, and while setting up the new server, I ran into a really frustrating issue with wp-cron that had a stupidly simple fix.

Some background: I setup several virtual hosts with Apache that redirected based on the domain name. This is a fairly common setup for running multiple domains from a single server. To test, I modified my local hosts file to redirect the domains to the new server. The actual DNS record was still pointing to the old server until I had everything ready. This becomes important.

Everything seemed to be working correctly but when I’d run a BackWPUp job, nothing would happen. It would say the job was started, but it wouldn’t show me the job running page. It wouldn’t do anything.

Some searching seemed to indicate that this was related to wp-cron. And indeed, wp-cron was not running. Scheduled posts wouldn’t get posted. But none of my searches turned up anything. Wp-cron just wouldn’t run and there was no reason why.

Some digging showed that wp-cron wasn’t even in the access log. In the default setup, wp-cron gets called when someone visits your site. But it gets called via a callback to domain name/wp-cron. This means the server sends the request to the old server if you haven’t updated your DNS.

The stupidly simple fix? Add the virtual host domains to the /etc/hosts (or wherever, depending on your server) with the IP set to the local IP.* Boom. Everything works. It took me an embarrassingly long time to figure this out.

*Alternatively, you can just update the DNS to point to the new server when you’ve hit this point.

Leave a Reply

Your email address will not be published. Required fields are marked *