WordPress automatic updates – the hassle free way

I have quite a few wordpress sites under management, and updating the plugins and themes can get quite tedious. This script will update all of them automatically (you will need SSH and CRON access for this) to whatever time-frame you set it to. The trick is to use “wp-cli” which is a command line toolset for WordPress that lets you do just about anything (you can even reset admin passwords so be careful who has access to this stuff).

I update all of the sites every day and have been doing this for years without any issues. I get a cron email every day telling me which plugins were updated and if anything happened.

Word of caution: there is potential that you can mess up your site, especially with these kinds of updates. I highly recommend you setup an external monitoring system like Nagios/Pingdom that will let you know if there is a site issue.

Step 1: If you are running on a Unix server, download the wp-cli.phan toolset from: wp-cli.org

You can install this file anywhere, just make sure it’s not internet accessible (keep it outside of /var/www typically)

See if it downloaded properly:

Now we need to create a shell script that will do the updating for us (via a cron job).

Now we need to make that file executable:

Now let’s test it out!

Great!  The last part is to add it to cron so this will run every night. We are going to use the www-data user and add this to their cron so it runs as the web user.

NOTE: this user might be different for you, if you use Nginx the username could be nginx. If you try to add a cron job to a non-existent user, it will tell you.

What this says is every night at 2:30AM run the update script as the www-data user (we don’t want to run this as root, it will break things)

That’s it, you can add as many blogs/directories as you like to the update_wordpress.sh file and it will update them as well.

One thing to note, you will get an email every night only if you have an email delivery program setup. I personally use Postfix since it’s very easy to setup. You will need to setup an email alias for this user.

If you have a custom theme this might not work properly, but it will error out when you test it.