cPanel Linux

Updating multiple WordPress installations, themes and plugins

If you have huge amount of WordPress installations on your server and you wish to update them all at once this is a solution for you.
Required:

  • SSH access
  • WP-CLI

Install WP-cli

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && chmod +x wp-cli.phar && sudo mv wp-cli.phar /home/wp

cPanel

Updating WP cores
for i in `ls /var/cpanel/users/`; do sudo -H -u $i bash -c "find /home/$i/public_html -name 'wp-admin' -execdir /usr/local/bin/php /home/wp core update \;" ; done
Updating WP Plugins
for i in `ls /var/cpanel/users/`; do sudo -H -u $i bash -c "find /home/$i/public_html -name 'wp-admin' -execdir /usr/local/bin/php /home/wp plugin update-all \;" ; done
Updating Themes
for i in `ls /var/cpanel/users/`; do sudo -H -u $i bash -c "find /home/$i/public_html -name 'wp-admin' -execdir /usr/local/bin/php /home/wp theme update-all \;" ; done
/home/wp is WP-CLI location
This will find all cpanel users and its wordpress installation paths (if any present), and then will run wp-cli under the user of that wordpress installation. This way ownership of files remains correct. And you won’t have any race condition warnings like you do when run wp cli as root.

Non-cPanel servers

If you do not have cPanel server you need just to replace ls var/cpanel/users with users
for i in `users`; do sudo -H -u $i bash -c "find /home/$i/public_html -name 'wp-admin' -execdir /usr/local/bin/php /home/wp core update \;" ; done
This path needs to be path to PHP-cli /usr/local/bin/php
Because wp-cli won’t work if ran with cgi-fcgi
Also you may need to replace path /home/$i/public_html with your user directory location, $i is name of user.

About the author

Luka Paunovic

I am Linux System Administrator and student of Business economics at John Naisbitt University.
Love to blog and read blogs.

Add Comment

Click here to post a comment

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