使用WP-CLI管理WordPress入门指南

This article provides an introductory guide to WP-CLI, a command-line tool that was created to make developers’ lives easier, allowing them to manage a WordPress site through the command line rather than through the usual admin interface.

本文提供了WP-CLI的入门指南,WP-CLI是一种命令行工具,旨在使开发人员的生活更轻松,使他们可以通过命令行而不是通常的管理界面来管理WordPress网站。

WP-CLI was created by Daniel Bachhuber over a decade ago. Since then, it’s become an indispensable tool in every advanced WordPress developer’s arsenal — “deployed and relied upon by almost every major user of WordPress”, according to Matt Mullenweg. Since 2016, WP-CLI has been an official WordPress CLI tool.

WP-CLI由Daniel Bachhuber于十年前创立。 自那时以来,它已经成为每一个先进的WordPress开发者的武器库中不可或缺的工具- “部署和由WordPress的几乎每一个主要的用户依靠”,根据马特·查尔斯·穆伦维格 。 自2016年以来,WP-CLI一直是官方的WordPress CLI工具

WP-CLI is used for installing and setting up a WordPress website, changing its options, administering users, and a host of other things. It can be leveraged to significantly speed up developers’ workflows.

WP-CLI用于安装和设置WordPress网站,更改其选项,管理用户以及许多其他事情。 可以利用它来显着加快开发人员的工作流程。

WP-CLI comes as a phar file — short for PHP Archive. It’s a standard for packaging multiple PHP files and other resources as a single application — for simpler distribution and installation.

WP-CLI作为phar文件提供phar Archive的缩写。 它是将多个PHP文件和其他资源打包为一个应用程序的标准-以便更轻松地分发和安装。

安装 (Installation)

WP-CLI presumes, obviously, that we have access to the system shell. This will be pretty straightforward on Linux and macOS systems — particularly on servers — as WordPress is served almost universally from Linux machines. If we have dedicated server hosting, or cloud hosting like AWS, Alibaba Cloud, etc., or if we’re using a VPS from Digital Ocean, Vultr, Linode and the like, SSH comes as a default access option, but these days many shared hosts offer SSH access options. (Some might even come with WP-CLI preinstalled.)

显然,WP-CLI假定我们可以访问系统外壳。 在Linux和macOS系统上,尤其是在服务器上,这将非常简单,因为WordPress几乎都是从Linux计算机上提供的。 如果我们拥有专用的服务器托管,或诸如AWS,阿里云等的云托管,或者我们使用的是Digital Ocean,Vultr,Linode等的VPS,则SSH是默认的访问选项,但如今很多时候共享主机提供SSH访问选项。 (有些甚至可能预装了WP-CLI。)

For Windows users, WP-CLI can be installed via Composer, but we recommend readers get themselves acquainted with Windows Subsystem for Linux, because it makes it possible to have a native Linux environment available, along with Bash, package manager like APT, etc. WordPress is a PHP app, and PHP’s native environment is Linux.

对于Windows用户,可以通过Composer安装WP-CLI,但是我们建议读者熟悉Linux的Windows子系统 ,因为它可以使本机Linux环境以及Bash,包管理器(如APT)等成为可能。 WordPress是一个PHP应用程序,而PHP的本机环境是Linux。

Further code samples presume we’re using Linux or a Unix-type system.

进一步的代码示例假定我们正在使用Linux或Unix类型的系统。

To fetch the WP-CLI phar archive, we usecurl or wget:

要获取WP-CLI phar存档,我们使用usecurlwget

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

This downloads our archive to the current directory. Then we make it executable:

这会将我们的存档下载到当前目录。 然后我们使其可执行:

chmod +x wp-cli.phar

We them move it so it’s available as a wp command:

我们将它们移动,因此可以作为wp命令使用:

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

Now we have a wp command available:

现在我们有一个wp命令可用:

Now, upon typing the wp command, it displays all the options for us, and possible parameters. One caveat: if we’re running as the root user, we need to add --allow-root to our commands:

现在,在键入wp命令后,它将显示我们的所有选项以及可能的参数。 一个警告:如果我们以root用户身份运行,则需要在命令中添

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值