Keeping your WordPress installation, plugins and theme up to date is very important. You should constantly update WordPress as soon as a new version is released. New versions bring you new features, bug fixes, stability improvements and most importantly, security fixes. If you don’t update your WordPress site, it’s very likely that your site will be hacked at some point. In this case, you can lose website content, your customers, lose your Google rank, your site can get damaged, your server can be used to send spam, and much more. Thus, WordPress updates should be at the top of the list when it comes to the security of your Linux virtual server.
In this article, we will show you how to update your WordPress installation to the latest version available using the Linux command line.
Log in to the server via SSH as the root user and first of all make sure to back up your website and MySQL database.
Back up your MySQL database.
mysqldump -u DBUSER -p DBNAME > /root/database_dump.sql
Replace DBUser with the actual MySQL user and DBNAME with the WordPress database name. After executing the command, you will be prompted for the database password.
Now, back up the website files with the following command
rsync -Waq /path/to/your/site /path/to/backup
Don’t forget to replace the paths in the command with real paths.
Now that we have backed up the site and database files, we can start the update. If something goes wrong, you can easily restore your WordPress website from a backup.
Change your current working directory to the document root and download the WordPress archive from their official site
cd /var/www/html wget https://wordpress.org/latest.zip
Unpack the archive
This will create a new directory “WordPress”
Remove the ‘wp-admin ”and” wp-includeыs ”folders from your old WordPress installation
rm -rf oldwordpress/wp-includes rm -rf oldwordpress/wp-admin
Replace ‘oldwordpress’ with the real name of your WordPress directory.
Now, move all the contents of the newly created ‘WordPress’ directory to the old WordPress directory and overwrite all files and directories.
mv wordpress/* oldwordpress/
Delete the archive and empty WordPress directory
rm -rf wordpress rm -f latest.zip
This step completes the WordPress command line update process. Now you need to access http://yourdomain.ru/wp-admin/upgrade.php to run the kernel upgrade script and database upgrade.
WordPress can also be upgraded using the CLI using the WP-CLI.