博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何安装和使用WP-CLI来管理WordPress网站
阅读量:2505 次
发布时间:2019-05-11

本文共 8022 字,大约阅读时间需要 26 分钟。

Speeding up your work process should be one of your top priorities. Simply put, if you do more work in less time, then you will have more time to work on more projects, study and rest.

加快工作流程应该是您的首要任务之一。 简而言之,如果您用更少的时间做更多的工作,那么您将有更多的时间从事更多的项目,学习和休息。

is one of the command line tools specifically made to manage your WordPress websites through the command line. With a few simple commands, you can manage WordPress without even needing to login to your WordPress admin and navigate through the pages.

是专门用于通过命令行管理WordPress网站的命令行工具之一。 使用一些简单的命令,您甚至无需登录WordPress管理员并浏览页面即可管理WordPress。

WordPress WP-CLI

In this tutorial, we’re going to learn exactly what WP-CLI is, how to install it and an overview of the basic commands of this tool.

在本教程中,我们将确切学习WP-CLI是什么,如何安装它以及该工具的基本命令概述。

WP-CLI will be particularly useful if you are a WordPress developer, System Administrator or run a business built around WordPress. This command line tool will greatly help you do more in less time. For example, taking backups, updating WordPress and plugins, publishing content and querying databases can be accomplished relatively quickly.

如果您是WordPress开发人员,系统管理员或围绕WordPress建立业务,WP-CLI将特别有用。 此命令行工具将极大地帮助您在更短的时间内完成更多工作。 例如,可以相对快速地完成备份,更新WordPress和插件,发布内容和查询数据库。

WP-CLI的要求 (Requirements of WP-CLI)

To install WP-CLI, make sure you have a hosting account with SSH access. Most shared hosting providers do not give you access to SSH. Providers like DigitalOcean, Linode and AWS are ideal for this if you love to spin up your own servers.

要安装WP-CLI,请确保您拥有具有SSH访问权限的托管帐户。 大多数共享主机提供商都不允许您访问SSH。 如果您喜欢启动自己的服务器,则DigitalOcean,Linode和AWS等提供商非常适合此目的。

Other requirements are basic:

其他要求是基本的:

  1. PHP 5.3.2 or later.

    PHP 5.3.2或更高版本。
  2. WordPress 3.4 or later.

    WordPress 3.4或更高版本。
  3. UNIX like environment like Linux.

    像Linux这样的UNIX环境。

如何安装WP-CLI (How to Install WP-CLI)

第1步 (Step 1)

First connect to your server’s command line through SSH. You can install the latest version of WP-CLI using the cURL or wget command. The WP-CLI installation file is available as a phar file and the latest version can be found at:

首先通过SSH连接到服务器的命令行。 您可以使用cURL或wget命令安装最新版本的WP-CLI。 WP-CLI安装文件以phar文件形式提供,最新版本可在以下位置找到:

Using the cURL command, type:

使用cURL命令,键入:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

This will download and extract the WP-CLI files to your root user directory.

这将下载WP-CLI文件并将其解压缩到您的根用户目录。

第2步 (Step 2)

Next, we will set the permissions to make it executable. Enter the following command:

接下来,我们将设置权限以使其可执行。 输入以下命令:

chmod +x wp-cli.phar

第三步 (Step 3)

Optionally, we can move wp-cli.phar to a folder and rename it to wp. This will help us use the WP-CLI commands by just typing ‘wp’ at the start of the commands.

(可选)我们可以将wp-cli.phar移至文件夹并将其重命名为wp。 通过在命令开头键入“ wp”,这将有助于我们使用WP-CLI命令。

sudo mv wp-cli.phar /usr/local/bin/wp

That’s it! Now we can jump in to use many of the WP-CLI commands.

而已! 现在我们可以跳入使用许多WP-CLI命令。

基本的WP-CLI命令 (Basic WP-CLI Commands)

To keep it simple, we’re going to overview the basic WP-CLI commands. You can explore more .

为简单起见,我们将概述基本的WP-CLI命令。 您可以探索更多 。

使用WP-CLI帮助系统 (Using the WP-CLI Help System)

WP-CLI comes with a full help system that you can access by typing “wp help”, for example:

WP-CLI带有完整的帮助系统,您可以通过键入“ wp help”来访问它,例如:

wp help cache

Will display information as:

将信息显示为:

名称 (NAME)

wp cache

描述 (DESCRIPTION)

Manage the object cache.

概要 (SYNOPSIS)

wp cache 

子命令 (SUBCOMMANDS)

add – Add a value to the object cache. decr – Decrement a value in the object cache. delete – Remove a value from the object cache. flush – Flush the object cache. get – Get a value from the object cache. incr – Increment a value in the object cache. replace – Replace an existing value in the object cache. set – Set a value to the object cache. type – Attempts to determine which object cache is being used.

add –向对象缓存添加一个值。 decr –减少对象缓存中的值。 delete –从对象缓存中删除一个值。 flush –刷新对象缓存。 get –从对象缓存中获取一个值。 incr –在对象缓存中增加一个值。 replace –替换对象缓存中的现有值。 set –为对象缓存设置一个值。 type –尝试确定正在使用哪个对象缓存。

例子 (EXAMPLES)

wp cache set my_key my_value my_group 300                                                                                                wp cache get my_key my_group

You can use the help system to understand what you can do with the commands and their respective subcommands.

您可以使用帮助系统来了解如何使用命令及其相应的子命令。

使用WP-CLI安装WordPress (Installing WordPress with WP-CLI)

If you haven’t installed WordPress by using any other method on your server, then you can easily do so using WP-CLI command wp core install. Along with that command we need to pass parameters such as URL, Title, Admin Username, Password and Admin Email.

如果您尚未在服务器上使用任何其他方法来安装WordPress,则可以使用WP-CLI命令wp core install轻松地进行wp core install 。 与该命令一起,我们需要传递诸如URL,标题,管理员用户名,密码和管理员电子邮件之类的参数。

wp core install --url="your_domain"  --title="Blog Title" --admin_user="admin username" --admin_password="enter_your_password" --admin_email="enter_your_email"

使用WP-CLI安装主题 (Installing Themes with WP-CLI)

Importing and installing themes is much quicker through WP-CLI than going into WordPress admin, searching and then activating it.

通过WP-CLI导入和安装主题比进入WordPress管理,搜索然后激活它要快得多。

It connects your server directly to the and imports the theme in a matter of a few seconds. For example, to install a theme like TwentyTen, we will use the following command:

它将您的服务器直接连接到并在几秒钟内导入主题。 例如,要安装类似TwentyTen的主题,我们将使用以下命令:

wp theme install twentyten

Similarly, to install P2 theme, our command will become:

同样,要安装P2主题,我们的命令将变为:

wp theme install p2

To activate the themes on your WordPress website, you will need to use the following command:

要在WordPress网站上激活主题,您将需要使用以下命令:

wp theme activate p2

使用WP-CLI安装插件 (Installing Plugins with WP-CLI)

Just like the themes, plugins can also be installed right from the . Installation is seamless and takes almost no time.

就像主题一样,插件也可以直接从安装。 安装是无缝的,几乎不需要时间。

For example: wp plugin install woocommerce

例如: wp plugin install woocommerce

The above command will install the WooCommerce plugin on your website. To activate it, we will use the command:

上面的命令将在您的网站上安装WooCommerce插件。 要激活它,我们将使用以下命令:

wp plugin activate woocommerce

Similarly, to deactivate any plugin, the command becomes:

同样,要停用任何插件,命令将变为:

wp plugin deactivate woocommerce

使用WP-CLI更新WordPress核心,主题和插件 (Updating WordPress Core, Themes and Plugins with WP-CLI)

Repetitive and often time consuming task of updating the WordPress core, themes and plugins can be easily carried out through the command line.

更新WordPress核心,主题和插件的重复性任务通常很耗时,可以通过命令行轻松完成。

To update the WordPress core to the latest stable release of WordPress, the command is:

要将WordPress核心更新为WordPress的最新稳定版本,命令为:

wp core update

If you want to update to a specific version, for example you have WordPress 3.7 and want to move to WordPress 4.0 instead of WordPress 4.3, use the command:

如果要更新到特定版本,例如,您拥有WordPress 3.7,并且想要迁移到WordPress 4.0而不是WordPress 4.3,请使用以下命令:

wp core update --version=4.0

Or, if for any reason you want to revert back your WordPress site to the previous version, the command is:

或者,如果出于任何原因您想将WordPress网站恢复为以前的版本,则命令为:

wp core update --version=3.9 --force

To update plugins, you can either define one plugin to update or better still, update all the plugins in one go.

要更新插件,您可以定义一个要更新的插件,或者更好的方法是一次性更新所有插件。

wp plugin update woocommercewp plugin update --all

A similar method applies to the themes. You can update WordPress themes through WP-CLI with following command

类似的方法适用于主题。 您可以使用以下命令通过WP-CLI更新WordPress主题

wp theme update twentytenwp theme update --all

结论 (Conclusion)

WP-CLI is indeed a powerful tool that can be used to manage your WordPress sites through the command line. There are also many more commands to manage your database, take backups, manage posts, comments and WordPress multisite It definitely speeds up your tasks, and makes it really easy to manage the sites. Luckily, there are hosting providers that provide WP-CLI by default on their WordPress installations ().

WP-CLI确实是一个功能强大的工具,可用于通过命令行管理WordPress网站。 还有许多其他命令可用于管理数据库,进行备份,管理帖子,评论和WordPress多站点。这无疑加快了您的工作速度,并使其真正易于管理。 幸运的是,有默认情况下在其WordPress安装中提供WP-CLI的托管服务提供商( )。

翻译自:

转载地址:http://tkrgb.baihongyu.com/

你可能感兴趣的文章
iOS开发中遇到的问题整理 (一)
查看>>
Linux(SUSE 12)安装jboss4并实现远程访问
查看>>
Neutron在给虚拟机分配网络时,底层是如何实现的?
查看>>
netfilter/iptables全攻略
查看>>
Overlay之VXLAN架构
查看>>
Eclipse : An error occurred while filtering resources(Maven错误提示)
查看>>
在eclipse上用tomcat部署项目404解决方案
查看>>
web.xml 配置中classpath: 与classpath*:的区别
查看>>
suse如何修改ssh端口为2222?
查看>>
详细理解“>/dev/null 2>&1”
查看>>
suse如何创建定时任务?
查看>>
suse搭建ftp服务器方法
查看>>
centos虚拟机设置共享文件夹并通过我的电脑访问[增加smbd端口修改]
查看>>
文件拷贝(IFileOperation::CopyItem)
查看>>
MapReduce的 Speculative Execution机制
查看>>
大数据学习之路------借助HDP SANDBOX开始学习
查看>>
Hadoop基础学习:基于Hortonworks HDP
查看>>
为什么linux安装程序 都要放到/usr/local目录下
查看>>
Hive安装前扫盲之Derby和Metastore
查看>>
永久修改PATH环境变量的几种办法
查看>>