{"id":762,"date":"2017-03-17T00:00:00","date_gmt":"2017-03-17T00:00:00","guid":{"rendered":"http:\/\/blog.hostinger.io\/hostinger-tutorials\/uncategorized\/wp-cli\/"},"modified":"2026-03-09T19:20:08","modified_gmt":"2026-03-09T19:20:08","slug":"wp-cli","status":"publish","type":"post","link":"\/ng\/tutorials\/wp-cli\/","title":{"rendered":"What is WP-CLI and how to use it for managing a WordPress site"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p>WordPress is one of the most user-friendly content management systems (CMS) due to its intuitive admin dashboard. However, managing a WordPress site can become more complex, especially as your website grows. Whether you are a regular user or a developer, you need to manage themes, plugins, and updates.<\/p><p>Mastering tools such as the WordPress Command-Line Interface (WP-CLI) can be a game-changer. This WP-CLI WordPress tutorial offers a comprehensive guide, covering everything from its installation to using it effectively for WordPress website management.<\/p><p>By the end, you&rsquo;ll have a solid grasp of WP-CLI&rsquo;s capabilities, equipping you to manage WordPress websites more efficiently.<\/p><p class=\"has-text-align-center\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Mega-WordPress-Cheat-EN.pdf\">Download all-in-one WordPress cheat sheet<\/a><\/p><p>\n\n\n\n<div class=\"protip\"><div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                   What Is WP-CLI?\n                <\/p>\n            <\/div>\n            <p class=\"protip__content\"><br>\nWP-CLI is the command-line interface for WordPress, enabling users to manage their WordPress sites without a web browser. It&rsquo;s a set of command-line tools for handling WordPress tasks, including managing themes, plugins, and databases.<br>\n<\/p><\/div>\n\n\n\n<\/p><p>While the WordPress admin dashboard offers a user-friendly experience, WP-CLI elevates website management. Using the command-line interface, you can perform tasks more swiftly and even automate various site maintenance aspects.<\/p><p>WP-CLI is particularly useful for <a href=\"\/ng\/tutorials\/how-to-become-wordpress-developer\/\">WordPress developers<\/a> who handle multiple sites, facilitating streamlined management directly from the command line.<\/p><h3 class=\"wp-block-heading\" id=\"h-what-are-the-benefits-of-wp-cli\">What Are the Benefits of WP-CLI?<\/h3><p>WP-CLI offers various advantages for both regular users and freelancers. Here&rsquo;s why you should consider using the WordPress command-line interface:<\/p><ul class=\"wp-block-list\">\n<li><strong>Efficiency <\/strong>&ndash; WP-CLI lets you perform tasks in seconds that could take minutes or even hours via the traditional WordPress admin dashboard.<\/li>\n\n\n\n<li><strong>Bulk actions <\/strong>&ndash; this tool helps you manage multiple plugins, themes, or websites with a single command. It is particularly beneficial for freelancers who manage clients&rsquo; sites and want to perform bulk actions quickly.<\/li>\n\n\n\n<li><strong>Remote management <\/strong>&ndash; with WP-CLI, you can remotely maintain WordPress websites, meaning there&rsquo;s no need to log in to each admin dashboard individually.<\/li>\n\n\n\n<li><strong>Automated backups <\/strong>&ndash; WP-CLI enables you to create automated backup routines for your WordPress site. This is handy for those with WP-CLI support in their <a href=\"\/ng\/tutorials\/backup-wordpress\/\">WordPress backup solutions<\/a>.<\/li>\n\n\n\n<li><strong>Advanced customizations <\/strong>&ndash; while WordPress&rsquo; graphical interface is user-friendly, it can be limiting for more complex tasks. WP-CLI allows for advanced customization that isn&rsquo;t possible through the dashboard.<\/li>\n<\/ul><h3 class=\"wp-block-heading\" id=\"h-wp-cli-v2\">WP-CLI v2<\/h3><p>WP-CLI has come a long way, and its latest stable version is <strong>WP-CLI v2<\/strong>,<strong> <\/strong>with the newest release being <strong>2.8.1<\/strong>. This release brings updated features and improved stability to help you manage your WordPress site efficiently.<\/p><p>Here are the minimum requirements for running WP-CLI v2:<\/p><ul class=\"wp-block-list\">\n<li>PHP 5.6 or later<\/li>\n\n\n\n<li>WordPress 3.7 or later<\/li>\n\n\n\n<li>UNIX-like environment (OS X, Linux, FreeBSD, Cygwin) &ndash; limited support in Windows.<\/li>\n<\/ul><p>Updating to the latest version is recommended for several reasons:<\/p><ul class=\"wp-block-list\">\n<li>Newer versions often come with security patches.<\/li>\n\n\n\n<li>Access to new commands and functionalities that older versions may not support.<\/li>\n\n\n\n<li>Improved speed and efficiency in executing commands.<\/li>\n<\/ul><p><div class=\"announcement-block announcement-block--important\">\n            <span class=\"announcement-block__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                          d=\"M12 22.5C17.799 22.5 22.5 17.799 22.5 12C22.5 6.20101 17.799 1.5 12 1.5C6.20101 1.5 1.5 6.20101 1.5 12C1.5 17.799 6.20101 22.5 12 22.5ZM13.637 7.65198C13.637 6.74791 12.9041 6.01501 12 6.01501C11.0959 6.01501 10.363 6.74791 10.363 7.65198C10.5335 9.53749 10.875 13.383 10.875 13.383C10.875 14.0043 11.3787 14.508 12 14.508C12.6213 14.508 13.125 14.0043 13.125 13.383V13.38L13.637 7.65198ZM11.9927 15.714C11.3714 15.714 10.8677 16.2177 10.8677 16.839C10.8677 17.4603 11.3714 17.964 11.9927 17.964H12.0073C12.6286 17.964 13.1323 17.4603 13.1323 16.839C13.1323 16.2177 12.6286 15.714 12.0073 15.714H11.9927Z\"\n                          fill=\"#FEA419\"\/>\n                <\/svg>\n                Important\n            <\/span>\n            <p class=\"announcement-block__content\">\n                <br>\n<strong>Important!<\/strong> Although WP-CLI can be installed in older PHP and WordPress versions, we recommend updating to the latest releases for enhanced security.<br>\n\n            <\/p><\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-install-wp-cli\">How to Install WP-CLI?<\/h2><p>Installing WP-CLI is straightforward whether you&rsquo;re on a hosting plan or a local Linux environment.<\/p><p>Fortunately, WP-CLI is already installed if you&rsquo;re using Hostinger&rsquo;s Premium plan or above for <a href=\"\/ng\/web-hosting\">web hosting<\/a> and <a href=\"\/ng\/wordpress-hosting\">managed WordPress hosting<\/a>.&nbsp;<\/p><figure class=\"wp-block-image size-large\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-wordpress-hosting\" href=\"\/ng\/wordpress-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"600\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/06\/New-WP_in-text-banner.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-111781\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/06\/New-WP_in-text-banner.png\/w=2048,fit=scale-down 2048w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/06\/New-WP_in-text-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/06\/New-WP_in-text-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/06\/New-WP_in-text-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/06\/New-WP_in-text-banner.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/06\/New-WP_in-text-banner.png\/w=1536,fit=scale-down 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/a><\/figure><p>To use it, activate <a href=\"\/ng\/tutorials\/ssh-tutorial-how-does-ssh-work\/\">SSH<\/a> access on your <strong>hPanel<\/strong>. Here&rsquo;s how:<\/p><ol class=\"wp-block-list\">\n<li>Log in to your hPanel.<\/li>\n\n\n\n<li>Navigate to <strong>Advanced &rarr;<\/strong> <strong>SSH Access<\/strong> through the left sidebar.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/10\/hpanel-advanced-ssh-access.png\"><img decoding=\"async\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/10\/hpanel-advanced-ssh-access.png\/w=1024,h=1024,fit=scale-down\" alt=\"Selecting SSH Access in the hPanel's left sidebar under the Advanced section\"><\/a><\/figure><\/div><ol start=\"3\" class=\"wp-block-list\">\n<li>Click <strong>Enable <\/strong>in the <strong>SSH status <\/strong>section, and you&rsquo;re all set.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/10\/hpanel-advanced-ssh-access-enable-highlighted.png\"><img decoding=\"async\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/10\/hpanel-advanced-ssh-access-enable-highlighted.png\/w=1024,h=1024,fit=scale-down\" alt=\"SSH Access menu displaying an option to enable the currently inactive SSH status\"><\/a><\/figure><\/div><p>For those on <a href=\"\/ng\/vps-hosting\">VPS hosting<\/a> or any Linux environment, you can manually install WP-CLI using the steps below:<\/p><ol class=\"wp-block-list\">\n<li>Access your server using an <a href=\"\/ng\/tutorials\/how-to-use-putty-ssh\/\">SSH client like PuTTy<\/a>.<\/li>\n\n\n\n<li>Once logged in, download the WP-CLI <strong>PHAR <\/strong>file:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">curl -O https:\/\/raw.githubusercontent.com\/wp-cli\/builds\/gh-pages\/phar\/wp-cli.phar<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Verify that the <strong>PHAR <\/strong>file is working:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">php wp-cli.phar --info<\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li>Make the file executable:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">chmod +x wp-cli.phar<\/pre><ol start=\"5\" class=\"wp-block-list\">\n<li>Move the <strong>PHAR <\/strong>file to a location in your path, for example:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo mv wp-cli.phar \/usr\/local\/bin\/wp<\/pre><ol start=\"6\" class=\"wp-block-list\">\n<li>Complete the WP-CLI installation by executing the following command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">wp core install<\/pre><h2 class=\"wp-block-heading\" id=\"h-common-wp-cli-commands\">Common WP-CLI Commands<\/h2><p>After installing WP-CLI, familiarize yourself with its primary features. This command-line tool lets you accomplish many tasks efficiently. Mastering these WP-CLI commands will help you manage your WordPress site directly from the command line.<\/p><h3 class=\"wp-block-heading\" id=\"h-how-to-check-wp-cli-version\">How to Check WP-CLI Version<\/h3><p>To ensure you&rsquo;re running the current version of WP-CLI, you can check this tool&rsquo;s installed version routinely. Open your command-line tool and enter:<\/p><pre class=\"wp-block-preformatted\">wp cli version<\/pre><p>You&rsquo;ll see an output similar to:<\/p><pre class=\"wp-block-preformatted\">WP-CLI 2.8.1<\/pre><p>For more detailed information, including the <a href=\"\/ng\/tutorials\/what-is-php\/\">PHP<\/a> and MySQL version, you can use this command:<\/p><pre class=\"wp-block-preformatted\">wp --info<\/pre><p>The output will look like the following:<\/p><pre class=\"wp-block-preformatted\">PHP binary:     \/usr\/bin\/php8.2<br>PHP version:    8.2.0<br>php.ini used:   \/etc\/php\/8.1\/cli\/php.ini<br>MySQL binary:   \/usr\/bin\/mysql<br>MySQL version:  mysql  Ver 8.0.27-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))<br>SQL modes:<br>WP-CLI root dir:        \/home\/wp-cli\/<br>WP-CLI vendor dir:      \/home\/wp-cli\/vendor<br>WP_CLI phar path:<br>WP-CLI packages dir:    \/home\/wp-cli\/.wp-cli\/packages\/<br>WP-CLI global config:<br>WP-CLI project config:  \/home\/wp-cli\/wp-cli.yml<br>WP-CLI version: 2.8.1<br><\/pre><p>If you&rsquo;re on an outdated version, you can easily update WP-CLI by running the <strong>wp cli update <\/strong>command below:<\/p><pre class=\"wp-block-preformatted\">wp cli update<\/pre><p>The output will confirm the updated version, such as:<\/p><pre class=\"wp-block-preformatted\">Success: WP-CLI updated to 2.8.1<\/pre><h3 class=\"wp-block-heading\" id=\"h-how-to-access-the-list-of-wp-cli-commands-and-help-documentation\">How to Access the List of WP-CLI Commands and Help Documentation<\/h3><p>WP-CLI offers built-in documentation that contains essential command information. To view a complete list of available commands, type the following:<\/p><pre class=\"wp-block-preformatted\">wp<\/pre><p>You should see the output as follows:<\/p><pre class=\"wp-block-preformatted\">NAME\n  wp\nDESCRIPTION\n  Manage WordPress through the command-line.\nSYNOPSIS\n  wp &lt;command&gt;\nSUBCOMMANDS\n  cache                 Adds, removes, fetches, and flushes the WP Object Cache object.\n  cap                   Adds, removes, and lists capabilities of a user role.\n  cli                   Reviews current WP-CLI info, checks for updates, or views defined aliases.\n.....\n<\/pre><p>To exit the help page, press <strong>Q<\/strong>.<\/p><h3 class=\"wp-block-heading\" id=\"h-how-to-learn-more-about-a-specific-command\">How to Learn More About a Specific Command<\/h3><p>If you need details about a particular WP-CLI command, this tool offers comprehensive help documentation. This includes syntax, options, and examples.<\/p><p>For instance, to learn more about the <strong>wp user<\/strong> command, you can type:<\/p><pre class=\"wp-block-preformatted\">wp help user<\/pre><p>You&rsquo;ll see the output detailing usage, available arguments, and other essential information:<\/p><pre class=\"wp-block-preformatted\">NAME\n  wp user\nDESCRIPTION\n  Manages users, along with their roles, capabilities, and meta.\nSYNOPSIS\n  wp user &lt;command&gt;\nSUBCOMMANDS\n  add-cap          Adds a capability to a user.\n  add-role         Adds a role to a user.\n  create           Creates a new user.\n  ...\n<\/pre><p>You can also use the <strong>help<\/strong> command for subcommands. For example, to access the help page for the <strong>wp user update<\/strong> command, type:<\/p><pre class=\"wp-block-preformatted\">wp help user update<\/pre><h3 class=\"wp-block-heading\" id=\"h-how-to-install-wordpress-via-wp-cli\">How to Install WordPress via WP-CLI<\/h3><p><a href=\"\/ng\/tutorials\/how-to-install-wordpress\/\">Installing WordPress<\/a> through WP-CLI is quick and efficient. Before starting, ensure you&rsquo;ve created a <a href=\"\/ng\/tutorials\/what-is-mysql\/\">MySQL<\/a> database, as it&rsquo;s a prerequisite for WordPress installation.<\/p><p>With Hostinger, you can create a MySQL database in hPanel by navigating to <strong>Databases &rarr; Management<\/strong> via the sidebar.<\/p><p>Fill in the database&rsquo;s name, username, and password to create a new database.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/10\/hpanel-databases-management.png\"><img decoding=\"async\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/10\/hpanel-databases-management.png\/w=1024,h=1024,fit=scale-down\" alt=\"Database Management menu displaying fields to create a new MySQL database\"><\/a><\/figure><\/div><p>Alternatively, follow these steps to create a new MySQL database using the command line:<\/p><ol class=\"wp-block-list\">\n<li>Enter the MySQL shell by typing:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">mysql -u root -p<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Add a user and database name by typing the commands below. Replace <strong>username<\/strong> and<strong> databasename<\/strong> with your chosen values:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">CREATE USER 'username';\nCREATE DATABASE 'databasename';<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Grant all permissions for the user to modify the database:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">GRANT ALL PRIVILEGES ON databasename.* TO 'username' IDENTIFIED BY 'yourpassword';<\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li>Quit the MySQL shell by executing:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">quit<\/pre><p>After setting up the MySQL database, you can install WordPress from the command line. First, navigate to the <strong>public_html<\/strong> directory, where your website files should reside. To check the current directory, run the following:<\/p><pre class=\"wp-block-preformatted\">pwd<\/pre><p>If you&rsquo;re not in <strong>public_html<\/strong>, navigate accordingly:<\/p><pre class=\"wp-block-preformatted\">cd \/home\/username\/public_html<\/pre><p>Once you&rsquo;re in the<strong> public_html<\/strong> directory, proceed as follows:<\/p><ol class=\"wp-block-list\">\n<li>Download the latest WordPress core version using the following:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">wp core download<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Create a new <strong>wp-config.php<\/strong> with your database credentials:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">wp config create --dbname=databasename --dbuser=username --dbpass=password --dbhost=localhost --dbprefix=wp_<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Complete the WordPress installation using the <strong>wp core install<\/strong> command. Replace the placeholders with your details:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">wp core install --url=\"your_domain.com\" --title=\"Your Site Title\" --admin_user=\"username\" --admin_password=\"password\" --admin_email=\"you@domain.com\"<\/pre><p>The output will confirm the WordPress installation:<\/p><pre class=\"wp-block-preformatted\">Success: WordPress installed successfully.<\/pre><h3 class=\"wp-block-heading\" id=\"h-how-to-install-and-manage-wordpress-themes-via-wp-cli\">How to Install and Manage WordPress Themes via WP-CLI<\/h3><p>From listing all installed themes to installing a new one, WP-CLI streamlines these tasks effortlessly.<\/p><p>First, if you want to view all the currently installed themes, use:<\/p><pre class=\"wp-block-preformatted\">wp theme list<\/pre><p>This command will display an output like:<\/p><pre class=\"wp-block-preformatted\">+----------------+----------+--------+---------+\n| name           | status   | update | version |\n+----------------+----------+--------+---------+\n| astra          | inactive | none   | 4.3.1   |\n| twentytwentytwo| active   | none   | 1.4     |\n+----------------+----------+--------+---------+\n<\/pre><p>If you want to switch your active theme from Twenty Twenty-Two to Astra, for instance, use the following command:<\/p><pre class=\"wp-block-preformatted\">wp theme activate astra<\/pre><p>You will see an output similar to:<\/p><pre class=\"wp-block-preformatted\">Success: Switched to 'Astra' theme.<\/pre><p>You can also utilize WP-CLI to find themes from the WordPress repository. Here&rsquo;s an example to search for themes with <a href=\"\/ng\/tutorials\/what-is-bootstrap\/\">Bootstrap<\/a> support:<\/p><pre class=\"wp-block-preformatted\">wp theme search bootstrap<\/pre><p>You should see an output similar to the following:<\/p><pre class=\"wp-block-preformatted\">Success: Showing 10 of 630 themes.\n+-----------------------+-----------------------+--------+\n| name                  | slug                  | rating |\n+-----------------------+-----------------------+--------+\n| Bootstrap Fitness     | bootstrap-fitness     | 0      |\n| Bootstrap Coach       | bootstrap-coach       | 0      |\n| The Bootstrap Blog    | the-bootstrap-blog    | 100    |\n...\n<\/pre><p>For example, to install and activate The Bootstrap Blog theme, utilize the command below:<\/p><pre class=\"wp-block-preformatted\">wp theme install the-bootstrap-blog --activate<\/pre><p>If you want to see more <strong>wp theme<\/strong> subcommands, run the command as is. Here&rsquo;s the output you will see:<\/p><pre class=\"wp-block-preformatted\">usage: wp theme activate &lt;theme&gt;\n   or: wp theme auto-updates &lt;command&gt;\n   or: wp theme delete [&lt;theme&gt;...] [--all] [--force]\n...\n<\/pre><h3 class=\"wp-block-heading\" id=\"h-how-to-install-and-manage-wordpress-plugins-via-wp-cli\">How to Install and Manage WordPress Plugins via WP-CLI<\/h3><p>WP-CLI simplifies <a href=\"\/ng\/tutorials\/what-is-wordpress-plugin\/\">WordPress plugin<\/a> management from installation to deactivation. Let&rsquo;s go over how you can do this effortlessly.<\/p><p>To list currently installed plugins, use the following command:<\/p><pre class=\"wp-block-preformatted\">wp plugin list<\/pre><p>The output will look like this:<\/p><pre class=\"wp-block-preformatted\">+----------------+----------+--------+---------+\n| name           | status   | update | version |\n+----------------+----------+--------+---------+\n| akismet        | inactive | none   | 5.3     |\n| hello-dolly    | active   | none   | 1.7.2   |\n+----------------+----------+--------+---------+\n<\/pre><p>To <a href=\"\/ng\/tutorials\/wordpress\/how-to-install-wordpress-plugins\/\">install a new plugin<\/a> like WooCommerce, use the following <strong>wp plugin install<\/strong> command:<\/p><pre class=\"wp-block-preformatted\">wp plugin install woocommerce<\/pre><p>The output will confirm the installation:<\/p><pre class=\"wp-block-preformatted\">Success: Installed 1 of 1 plugins.<\/pre><p>To activate this newly installed WordPress plugin, use:<\/p><pre class=\"wp-block-preformatted\">wp plugin activate woocommerce<\/pre><p>You will then see:<\/p><pre class=\"wp-block-preformatted\">Success: Plugin 'woocommerce' activated.<\/pre><p>To install multiple plugins in one go, list the plugin slugs separated by a space:<\/p><pre class=\"wp-block-preformatted\">wp plugin install woocommerce gutenberg<\/pre><p>You can search for plugins in the WordPress repository using the command below. For example, to find WordPress cache plugins, type:<\/p><pre class=\"wp-block-preformatted\">wp plugin search cache<\/pre><p>This will generate an output similar to:<\/p><pre class=\"wp-block-preformatted\">Success: Showing 10 of 1010 plugins.\n+--------------------------------+--------------------------+--------+\n| name                           | slug                     | rating |\n+--------------------------------+--------------------------+--------+\n| LiteSpeed Cache                | litespeed-cache          | 96     |\n| W3 Total Cache                 | w3-total-cache           | 88     |\n| WP Fastest Cache               | wp-fastest-cache         | 98     |\n&hellip;\n<\/pre><p>For more <strong>wp plugin<\/strong> commands, run:<\/p><pre class=\"wp-block-preformatted\">wp plugin<\/pre><p>Here&rsquo;s a glimpse of the output you can expect:<\/p><pre class=\"wp-block-preformatted\">usage: wp plugin activate &lt;plugin&gt;  \n   or: wp plugin deactivate &lt;plugin&gt;  \n   or: wp plugin install &lt;plugin&gt; [--activate]  \n...\n<\/pre><h3 class=\"wp-block-heading\" id=\"h-how-to-update-wordpress-via-wp-cli\">How to Update WordPress via WP-CLI<\/h3><p>Updating your WordPress site, themes, and plugins is essential for performance and security. WP-CLI streamlines this process so your site can run the latest WordPress updates.<\/p><p>To <a href=\"\/ng\/tutorials\/how-to-update-wordpress\/\">update WordPress<\/a> to the latest version, run:<\/p><pre class=\"wp-block-preformatted\">wp core update<\/pre><p>You should see this output:<\/p><pre class=\"wp-block-preformatted\">Success: WordPress updated successfully.<\/pre><p>Next, check if a database update is needed by running:<\/p><pre class=\"wp-block-preformatted\">wp core update-db<\/pre><p>After the update, the output will confirm like this:<\/p><pre class=\"wp-block-preformatted\">Success: WordPress database updated.<\/pre><p>To verify your current WordPress version, use:<\/p><pre class=\"wp-block-preformatted\">wp core version<\/pre><p>Keeping your installed plugins up-to-date is also crucial. To update plugins, use:<\/p><pre class=\"wp-block-preformatted\">wp plugin update --all<\/pre><p>The output will read:<\/p><pre class=\"wp-block-preformatted\">Success: Updated x of x plugins.<\/pre><p>Make sure to update your themes, as well. To update all of them, run:<\/p><pre class=\"wp-block-preformatted\">wp theme update --all<\/pre><p>You&rsquo;ll see the following output:<\/p><pre class=\"wp-block-preformatted\">Success: Updated x of x themes.<\/pre><p>For targeted updates, replace the <strong>&ndash;all<\/strong> parameter with the specific theme or plugin slug.<\/p><h3 class=\"wp-block-heading\" id=\"h-how-to-change-wordpress-url-via-wp-cli\">How to Change WordPress URL via WP-CLI<\/h3><p>If you need to change your WordPress URL, WP-CLI simplifies this process.<\/p><p>To modify the home address, run the <strong>wp option update<\/strong> command, replacing <strong>http:\/\/example.com<\/strong> with your domain name.<\/p><pre class=\"wp-block-preformatted\">wp option update home \"http:\/\/example.com\"<\/pre><p>The output will confirm as follows:<\/p><pre class=\"wp-block-preformatted\">Success: Updated 'home' option.<\/pre><p>To adjust the site URL, use the same command but swap <strong>home<\/strong> with <strong>siteurl<\/strong>:<\/p><pre class=\"wp-block-preformatted\">wp option update siteurl \"http:\/\/example.com\"<\/pre><p>You&rsquo;ll see this output:<\/p><pre class=\"wp-block-preformatted\">Success: Updated 'siteurl' option.<\/pre><h3 class=\"wp-block-heading\" id=\"h-how-to-reinstall-wordpress-core-via-wp-cli\">How to Reinstall WordPress Core via WP-CLI<\/h3><p>In some cases, WordPress core files may get corrupted due to faulty updates or hacking attempts. WP-CLI provides a quick way to reinstall these core files without affecting your site&rsquo;s content and settings.<\/p><p>To <a href=\"\/ng\/tutorials\/how-to-reinstall-wordpress\/\">reinstall the WordPress core<\/a>, run the following command:<\/p><pre class=\"wp-block-preformatted\">wp core download --skip-content --force<\/pre><p>This command will skip downloading the <strong>wp-content<\/strong> directory and forcibly overwrite all other existing WordPress core files. The output should be:<\/p><pre class=\"wp-block-preformatted\">Success: WordPress downloaded.<\/pre><p>After downloading the core files, verify their integrity with this command:<\/p><pre class=\"wp-block-preformatted\">wp core verify-checksums<\/pre><p>If everything is clear, you should see:<\/p><pre class=\"wp-block-preformatted\">Success: WordPress installation verifies against checksums.<\/pre><h3 class=\"wp-block-heading\" id=\"h-how-to-manage-content-via-wp-cli\">How to Manage Content via WP-CLI<\/h3><p>Managing content on WordPress can be time-consuming if you&rsquo;re doing it manually. WP-CLI streamlines this process, enabling you to create, edit, and delete posts and media directly from the command line.<\/p><p><strong>Managing Posts<\/strong><\/p><p>To view a list of all posts, run the following command:<\/p><pre class=\"wp-block-preformatted\">wp post list<\/pre><p>You&rsquo;ll see an output similar to this:<\/p><pre class=\"wp-block-preformatted\">+----+--------------+-------------+---------------------+-------------+\n| ID | post_title   | post_name   | post_date           | post_status |\n+----+--------------+-------------+---------------------+-------------+\n| 1  | Hello world! | hello-world | 2023-06-06 03:39:33 | publish     |\n+----+--------------+-------------+---------------------+-------------+\n<\/pre><p>In this example, the post with the title <strong>Hello world!<\/strong> has an ID of <strong>1<\/strong>. To move this post to the trash, use:<\/p><pre class=\"wp-block-preformatted\">wp post delete 1<\/pre><p>The output will read:<\/p><pre class=\"wp-block-preformatted\">Success: Trashed post 1.<\/pre><p>To create a new post, run:<\/p><pre class=\"wp-block-preformatted\">wp post create --post_status=publish --post_title=\"This Post Was Created With WP-CLI\" --edit<\/pre><p>This command will open your system&rsquo;s default text editor. Once you&rsquo;ve added the content, save and exit the editor to see the output:<\/p><pre class=\"wp-block-preformatted\">Success: Created post 10.<\/pre><p>If you have a draft saved as a <strong>TXT <\/strong>file in the directory, you can import it directly with:<\/p><pre class=\"wp-block-preformatted\">wp post create .\/post.txt --post_title='Sample Post' --post_status=publish<\/pre><p>To generate multiple posts for testing, use:<\/p><pre class=\"wp-block-preformatted\">wp post generate --count=10<\/pre><p><strong>Managing Comments<\/strong><\/p><p>To approve a pending comment with a specific comment ID, use:<\/p><pre class=\"wp-block-preformatted\">wp comment approve 45<\/pre><p>The output will confirm with:<\/p><pre class=\"wp-block-preformatted\">Success: Approved comment 45.<\/pre><p>To list all the comments on a post, you can run:<\/p><pre class=\"wp-block-preformatted\">wp comment list --post_id=1234<\/pre><p>The output will display a list of comments associated with the post:<\/p><pre class=\"wp-block-preformatted\">+------------+---------------------+--------------+\n| comment_ID | comment_date        | comment_content |\n+------------+---------------------+--------------+\n| 34         | 2023-10-18 12:34:56 | Great post!    |\n+------------+---------------------+--------------+\n<\/pre><p><strong>Managing Media<\/strong><\/p><p>You can automate image imports using WP-CLI. For instance, to import all images from a folder named <strong>images_for_site<\/strong>, run:<\/p><pre class=\"wp-block-preformatted\">wp media import images-for-site\/*<\/pre><p>You should see an output like this:<\/p><pre class=\"wp-block-preformatted\">Imported file 'images-for-site\/image-1.jpg' as attachment ID 25.\nImported file 'images-for-site\/image-2.jpg' as attachment ID 26.\nSuccess: Imported 2 of 2 items.<\/pre><h3 class=\"wp-block-heading\" id=\"h-how-to-export-import-wordpress-via-wp-cli\">How to Export\/Import WordPress via WP-CLI<\/h3><p>WP-CLI offers simple yet powerful commands for exporting and importing WordPress data. Whether moving to a new host or backing up content, these commands make the process more efficient.<\/p><p>To export all your WordPress posts into an <strong>XML<\/strong> file, use the following command:<\/p><pre class=\"wp-block-preformatted\">wp export --dir=\/path\/to\/folder<\/pre><p>This will save the <strong>XML <\/strong>file to the specified directory, after which you&rsquo;ll see this output:<\/p><pre class=\"wp-block-preformatted\">Success: Wrote 'filename.xml' to '\/path\/to\/folder'.<\/pre><p>You can also export specific types of content, like pages or custom post types. For instance, to export all pages, use:<\/p><pre class=\"wp-block-preformatted\">wp export --post_type=page<\/pre><p>To import an <strong>XML <\/strong>file into WordPress, use:<\/p><pre class=\"wp-block-preformatted\">wp import \/path\/to\/file.xml --authors=create<\/pre><p>The <strong>&ndash;authors=create<\/strong> flag ensures that new authors mentioned in the <strong>XML<\/strong> file are created if they don&rsquo;t already exist. You&rsquo;ll see an output like:<\/p><pre class=\"wp-block-preformatted\">Success: Imported from 'file.xml'.<\/pre><p>You can also skip specific content or attachments during import. For example, to skip attachments, run:<\/p><pre class=\"wp-block-preformatted\">wp import \/path\/to\/file.xml --skip=attachment<\/pre><h3 class=\"wp-block-heading\" id=\"h-how-to-manage-database-using-wp-cli\">How to Manage Database Using WP-CLI<\/h3><p>Managing your WordPress database is crucial for optimal website performance. WP-CLI simplifies database tasks, offering a set of commands you can run directly from the command line.<\/p><p>To display all registered WordPress users, use this command:<\/p><pre class=\"wp-block-preformatted\">wp db query \"SELECT user_login, ID FROM wp_users;\"<\/pre><p>You&rsquo;ll get an output similar to this:<\/p><pre class=\"wp-block-preformatted\">+------------+----+\n| user_login | ID |\n+------------+----+\n| user       | 1  |\n+------------+----+\n<\/pre><p>To export your WordPress database, run:<\/p><pre class=\"wp-block-preformatted\">wp db export<\/pre><p>This saves an <strong>SQL <\/strong>file in your current directory. You&rsquo;ll see this output:<\/p><pre class=\"wp-block-preformatted\">Success: Exported to 'wordpress_db.sql'.<\/pre><p>To import an <strong>SQL <\/strong>file into your WordPress database, run the following:<\/p><pre class=\"wp-block-preformatted\">wp db import filename.sql<\/pre><p>After a successful import, you&rsquo;ll see:<\/p><pre class=\"wp-block-preformatted\">Success: Imported from 'filename.sql'.<\/pre><p>Periodically, it&rsquo;s beneficial to check your database for errors. Use this command for a quick repair:<\/p><pre class=\"wp-block-preformatted\">wp db repair<\/pre><p>You&rsquo;ll get this confirmation message:<\/p><pre class=\"wp-block-preformatted\">Success: Database repaired.<\/pre><p>Finally, keep your database optimized for smooth site performance. Execute the following:<\/p><pre class=\"wp-block-preformatted\">wp db optimize<\/pre><p>You&rsquo;ll see this output:<\/p><pre class=\"wp-block-preformatted\">Success: Database optimized.<\/pre><h3 class=\"wp-block-heading\" id=\"h-how-to-search-and-replace-using-wp-cli\">How to Search and Replace Using WP-CLI<\/h3><p>Bulk changes to your WordPress content, URLs, or database fields usually require manual effort or specialized <a href=\"\/ng\/tutorials\/wordpress-database-plugins\/\">database plugins<\/a>. However, WP-CLI offers a helpful search and replace command that automates this process.<\/p><p>To replace a string throughout your database, run:<\/p><pre class=\"wp-block-preformatted\">wp search-replace 'old-string' 'new-string'<\/pre><p>The output will confirm the action:<\/p><pre class=\"wp-block-preformatted\">Success: Replaced 'old-string' with 'new-string'.<\/pre><p>Before making permanent changes, you can perform a dry run to preview the results:<\/p><pre class=\"wp-block-preformatted\">wp search-replace 'old-string' 'new-string' --dry-run<\/pre><p>To run a case-insensitive search, include the <strong>&ndash;regex<\/strong> and <strong>&ndash;regex-flags<\/strong> options:<\/p><pre class=\"wp-block-preformatted\">wp search-replace 'old-string' 'new-string' --regex --regex-flags='i'<\/pre><p>You can specify which databases to search and replace in with this:<\/p><pre class=\"wp-block-preformatted\">wp search-replace 'old-string' 'new-string' --all-tables-with-prefix<\/pre><p>To change your website&rsquo;s domain, execute a dry run first to check what will be replaced:<\/p><pre class=\"wp-block-preformatted\">wp search-replace --dry-run 'website.net' 'website.com'<\/pre><p>If it all checks out, go ahead with the actual replacement command:<\/p><pre class=\"wp-block-preformatted\">wp search-replace 'website.net' 'website.com'<\/pre><p>The output should read:<\/p><pre class=\"wp-block-preformatted\">Success: Replaced 'website.net' with 'website.com'.<\/pre><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>Mastering WP-CLI is invaluable for efficient WordPress management. In this WP-CLI tutorial, we&rsquo;ve shared several examples of how to use the WordPress command-line interface.<\/p><p>Knowing these commands enables you to update your WordPress version, install plugins and themes, manage content, and optimize your database directly from WP-CLI.<\/p><p>As such, using WP-CLI can simplify your workflow and reduce the risk of human error when using a graphical user interface, particularly during critical tasks. That way, you can manage your WordPress sites confidently.<\/p><p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress is one of the most user-friendly content management systems (CMS) due to its intuitive admin dashboard. However, managing a WordPress site can become more complex, especially as your website grows. Whether you are a regular user or a developer, you need to manage themes, plugins, and updates. Mastering tools such as the WordPress Command-Line [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ng\/tutorials\/wp-cli\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":172,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"What is WP-CLI: Tutorial + Useful Commands","rank_math_description":"WP-CLI is a tool to manage a WordPress site through the terminal. Read this article to learn how to use it and get useful command examples.","rank_math_focus_keyword":"wp-cli","footnotes":""},"categories":[22637],"tags":[],"class_list":["post-762","post","type-post","status-publish","format-standard","hentry","category-wordpress"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/wp-cli","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-cli","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/wp-cli","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/wp-cli-dan-cara-menggunakannya","default":0},{"locale":"it-IT","link":"https:\/\/www.hostinger.com\/it\/tutorial\/wp-cli","default":0},{"locale":"nl-NL","link":"https:\/\/www.hostinger.com\/nl\/tutorials\/wp-cli","default":0},{"locale":"ja-JP","link":"https:\/\/www.hostinger.com\/jp\/tutorials\/wp-cli","default":0},{"locale":"ar-AE","link":"https:\/\/www.hostinger.com\/ae\/tutorials\/wp-cli","default":0},{"locale":"en-GB","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-cli","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-cli","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-cli","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/wp-cli","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-cli","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-cli","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/wp-cli","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-cli","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/762","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/users\/172"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/comments?post=762"}],"version-history":[{"count":43,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/762\/revisions"}],"predecessor-version":[{"id":145383,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/762\/revisions\/145383"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media?parent=762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/categories?post=762"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/tags?post=762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}