{"id":41798,"date":"2025-09-30T04:28:05","date_gmt":"2025-09-30T01:28:05","guid":{"rendered":"https:\/\/coma.lv\/2025\/09\/30\/how-to-use-wp-cli-to-manage-wordpress\/"},"modified":"2025-09-30T04:28:05","modified_gmt":"2025-09-30T01:28:05","slug":"how-to-use-wp-cli-to-manage-wordpress","status":"publish","type":"post","link":"https:\/\/coma.lv\/en\/2025\/09\/30\/how-to-use-wp-cli-to-manage-wordpress\/","title":{"rendered":"How to Use WP-CLI to Manage WordPress"},"content":{"rendered":"\n<p style=\"text-align: left;\" data-start=\"326\" data-end=\"614\"><strong data-start=\"326\" data-end=\"336\">WP-CLI<\/strong> is a powerful command-line tool that lets you manage a WordPress site without using a browser. With it you can quickly update plugins, work with posts, manage users, make backups and automate routine tasks.<\/p>\n<p style=\"text-align: left;\" data-start=\"616\" data-end=\"759\">It is ideal for both developers and administrators, especially if you work with several sites or large projects.<\/p>\n<h2 style=\"text-align: left;\" data-start=\"616\" data-end=\"759\">Why You Should Use WP-CLI<\/h2>\n<p style=\"text-align: left;\" data-start=\"844\" data-end=\"1036\">In everyday work with WordPress most actions are done through the admin area: you update plugins, install themes, create pages or users, clean the database and so on.<\/p>\n<p style=\"text-align: left;\" data-start=\"1038\" data-end=\"1155\">With WP-CLI you can do all this several times faster by simply typing commands in the terminal. This is convenient if you:<\/p>\n<ul style=\"text-align: left;\">\n<li data-start=\"1038\" data-end=\"1155\">maintain several sites and want to speed up routine operations;<\/li>\n<li data-start=\"1038\" data-end=\"1155\">automate processes (scripts, cron);<\/li>\n<li data-start=\"1038\" data-end=\"1155\">work on staging or production servers via SSH, where there is no access to the admin area or where you need to solve problems quickly;<\/li>\n<li data-start=\"1038\" data-end=\"1155\">want to perform bulk operations without clicking through the interface.<\/li>\n<\/ul>\n<p style=\"text-align: left;\">WP-CLI is also ideal for local development: you can test commands on a local server (for example, WAMP) without the risk of damaging a live site. All commands will be executed on your computer, not on a real server.<\/p>\n<h2 style=\"text-align: left;\">Installing WP-CLI on a Local Server (WAMP)<\/h2>\n<p style=\"text-align: left;\" data-start=\"1520\" data-end=\"1762\">For convenience, create a separate folder for WP-CLI, for example <code data-start=\"1633\" data-end=\"1644\">C:\\wp-cli<\/code>.  This lets you use WP-CLI globally and not tie it to a specific site. In the command line (Command Prompt), create the folder and go into it:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmkdir C:\\wp-cli\r\ncd C:\\wp-cli\r\n<\/pre>\n<p style=\"text-align: left;\" data-start=\"1805\" data-end=\"1862\">While in this folder, download WP-CLI with the command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncurl -O https:\/\/raw.githubusercontent.com\/wp-cli\/builds\/gh-pages\/phar\/wp-cli.phar\r\n<\/pre>\n<p style=\"text-align: left;\" data-start=\"1958\" data-end=\"2094\">Sometimes the downloaded file may have the extension <code data-start=\"2003\" data-end=\"2009\">.txt<\/code>, for example <code data-start=\"2020\" data-end=\"2037\">wp-cli.phar.txt<\/code>. In this case rename it back to <code data-start=\"2080\" data-end=\"2093\">wp-cli.phar<\/code>:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nrename wp-cli.phar.txt wp-cli.phar\r\n<\/pre>\n<p style=\"text-align: left;\" data-start=\"2143\" data-end=\"2182\">You can check that WP-CLI works with the command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nphp C:\\wp-cli\\wp-cli.phar --info\r\n<\/pre>\n<p style=\"text-align: left;\" data-start=\"2435\" data-end=\"2499\">This command will output information about the version of WP-CLI, PHP and your working environment<strong>.<\/strong><\/p>\n<p style=\"text-align: left;\" data-start=\"2229\" data-end=\"2332\">So that you do not have to type the full path to the <code data-start=\"2298\" data-end=\"2305\">.phar<\/code> every time, you can create a batch file <code data-start=\"2347\" data-end=\"2355\">wp.bat<\/code> in the same folder with the contents:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n@ECHO OFF\r\nphp &amp;quot;C:\\wp-cli\\wp-cli.phar&amp;quot; %*\r\n<\/pre>\n<p style=\"text-align: left;\" data-start=\"2672\" data-end=\"2721\">After that you can run the command simply as:<\/p>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\" style=\"text-align: left;\">\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs\">\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">wp --info\r\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>*On Windows 10\/11 the batch file sometimes does not handle <code data-start=\"2812\" data-end=\"2816\">%*<\/code> correctly, so for stable operation it is more convenient to call the <code data-start=\"2884\" data-end=\"2891\">.phar<\/code> directly through PHP.<\/p>\n<h2><span style=\"font-size: 28px; font-weight: 600; letter-spacing: 0px;\">Installing WP-CLI on a Live Site via SSH<\/span><\/h2>\n<\/div>\n<p style=\"text-align: left;\" data-start=\"2679\" data-end=\"2712\">Connect to the server via SSH:<\/p>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\" style=\"text-align: left;\">\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs\">\n<div class=\"bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs\">\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">ssh username@yourserver.com\r\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\">\n<p data-start=\"2755\" data-end=\"2820\">Go to the WordPress root, where the <code data-start=\"2804\" data-end=\"2819\">wp-config.php<\/code> file is located:<\/p>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\">\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs\">\n<div class=\"bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs\">\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">cd \/path\/to\/wordpress<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\">\n<p data-start=\"2857\" data-end=\"2910\">*Replace <code data-start=\"3156\" data-end=\"3176\">\/path\/to\/wordpress<\/code> with the real path to your WordPress installation.<\/p>\n<p data-start=\"2857\" data-end=\"2910\">If WP-CLI is installed globally, you can check that WP-CLI works with the command:<\/p>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\">\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs\">\n<div class=\"bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs\">\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">wp --info<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\">If it is not installed globally, call the <code data-start=\"3400\" data-end=\"3407\">.phar<\/code> directly:<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">php wp-cli.phar --info<\/pre>\n<h2 style=\"text-align: left;\">Working with WP-CLI<\/h2>\n<p style=\"text-align: left;\" data-start=\"3725\" data-end=\"3810\">WP-CLI should always be run <strong data-start=\"3758\" data-end=\"3776\">from the site root<\/strong>, where <code data-start=\"3792\" data-end=\"3807\">wp-config.php<\/code> is located.<\/p>\n<p style=\"text-align: left;\" data-start=\"3814\" data-end=\"3854\">On a local Windows server this is usually:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">C:\\wamp64\\www\\mysite\r\n<\/pre>\n<p style=\"text-align: left;\" data-start=\"3814\" data-end=\"3854\">On a live server via SSH:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncd \/path\/to\/wordpress\r\n<\/pre>\n<p style=\"text-align: left;\" data-start=\"3814\" data-end=\"3854\">*Replace <em>mysite<\/em> or <em>\/path\/to\/wordpress<\/em> with the real names of your folders.<\/p>\n<h2 style=\"text-align: left;\" data-start=\"3814\" data-end=\"3854\">Useful WP-CLI Commands<\/h2>\n<p style=\"text-align: left;\"><strong>Updating the WordPress Core<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nwp core update\r\n<\/pre>\n<p style=\"text-align: left;\"><strong>Installing and Activating a Plugin<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nwp plugin install contact-form-7 --activate\r\n<\/pre>\n<p style=\"text-align: left;\">*Replace <code data-start=\"312\" data-end=\"328\">contact-form-7<\/code> with the name of your plugin.<\/p>\n<p style=\"text-align: left;\"><strong>Installing and Activating a Theme<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nwp theme install twentytwentyfive --activate\r\n<\/pre>\n<p style=\"text-align: left;\">*Replace <code data-start=\"481\" data-end=\"499\">twentytwentyfive<\/code> with the theme you need.<\/p>\n<p style=\"text-align: left;\"><strong>Adding a New User<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nwp user create editor editor@example.com --role=editor --user_pass=123456\r\n<\/pre>\n<p style=\"text-align: left;\">*Replace <code data-start=\"302\" data-end=\"310\">editor<\/code>, <code data-start=\"312\" data-end=\"332\">editor@example.com<\/code> and <code data-start=\"335\" data-end=\"343\">123456<\/code> with the real username, email and password you want to use.<\/p>\n<p style=\"text-align: left;\"><strong>Database Backup<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nwp db export backup.sql\r\n<\/pre>\n<p style=\"text-align: left;\"><strong>Database Import<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nwp db import backup.sql\r\n<\/pre>\n<p style=\"text-align: left;\"><strong>Deactivating a Faulty Plugin<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nwp plugin deactivate problem-plugin\r\n<\/pre>\n<p style=\"text-align: left;\">*Replace <code data-start=\"883\" data-end=\"899\">problem-plugin<\/code> with the name of your plugin.<\/p>\n<h2 style=\"text-align: left;\">Summary<\/h2>\n<p style=\"text-align: left;\" data-start=\"100\" data-end=\"150\">Using WP-CLI lets you:<\/p>\n<ul style=\"text-align: left;\">\n<li data-start=\"100\" data-end=\"150\">speed up WordPress management;<\/li>\n<li data-start=\"100\" data-end=\"150\">safely update plugins, themes and the core;<\/li>\n<li data-start=\"100\" data-end=\"150\">manage users and the database directly through the terminal;<\/li>\n<li data-start=\"100\" data-end=\"150\">automate repetitive tasks;<\/li>\n<li data-start=\"100\" data-end=\"150\">quickly solve problems with plugins or other components without logging in to the admin area.<\/li>\n<\/ul>\n<p style=\"text-align: left;\">These capabilities make WP-CLI especially useful for developers, administrators and when working with several sites or large projects.<\/p>\n<hr \/>\n<p style=\"text-align: left;\"><em>Our specialization is WordPress website development and maintenance. Contact us for a free consultation \u2014 <a href=\"mailto:vadim@coma.lv\">vadim@coma.lv<\/a>, <a href=\"tel:+37129394520\">+371 29394520<\/a><\/em><\/p>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>WP-CLI is a powerful command-line tool that lets you manage a WordPress site without using a browser. With it you can quickly update plugins, work with posts, manage users, make backups and automate routine tasks. It is ideal for both developers and administrators, especially if you work with several sites or large projects. Why You [&hellip;]<\/p>\n","protected":false},"author":25,"featured_media":37646,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1225,1407],"tags":[],"class_list":["post-41798","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","category-tutorials"],"_links":{"self":[{"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/posts\/41798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/comments?post=41798"}],"version-history":[{"count":0,"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/posts\/41798\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/media\/37646"}],"wp:attachment":[{"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/media?parent=41798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/categories?post=41798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/tags?post=41798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}