WP-CLI是WordPress的命令行界面,WordPress是一种流行的内容管理系统(CMS),用于构建和管理网站。WP-CLI 提供了一组命令,可简化管理插件、更新主题和管理用户等任务。
在 Ubuntu 22.04 LTS Jammy Jellyfish 上安装 WP-CLI
第 1 步。首先,通过在终端中运行以下命令,确保所有系统软件包都是最新的。apt
<span class="pln">sudo apt update sudo apt upgrade sudo apt install wget apt</span><span class="pun">-</span><span class="pln">transport</span><span class="pun">-</span><span class="pln">https gnupg2 software</span><span class="pun">-</span><span class="pln">properties</span><span class="pun">-</span><span class="pln">common</span>
第 2 步。在 Ubuntu 22.04 上安装 WP-CLI。
- 方法 1.使用 Package Manager Ubuntu √安装 WP-CLI
默认情况下,WP-CLI 在 Ubuntu 22.04 基本存储库上可用。现在运行以下命令,将最新版本的WP-CLI安装到您的Ubuntu系统:
<span class="pln">sudo apt install wp</span><span class="pun">-</span><span class="pln">cli</span>
-
- 方法 2.从源代码√安装 WP-CLI
首先,使用命令下载:
wp-cli.phar
wget
<span class="pln">wget https</span><span class="pun">:</span><span class="com">//raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar</span>
接下来,使 WP-CLI 包可执行,并运行以下命令:
<span class="pln">chmod </span><span class="pun">+</span><span class="pln">x wp</span><span class="pun">-</span><span class="pln">cli</span><span class="pun">.</span><span class="pln">phar</span>
将其移动到路径中的某个位置。例如:
<span class="pln">sudo mv wp</span><span class="pun">-</span><span class="pln">cli</span><span class="pun">.</span><span class="pln">phar </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">wp</span>
要验证安装,请运行以下命令:
<span class="pln">wp </span><span class="pun">--</span><span class="pln">info</span>
输出:
<span class="pln">OS</span><span class="pun">:</span> <span class="typ">Linux</span> <span class="lit">5.10</span><span class="pun">.</span><span class="lit">60.1</span><span class="pun">-</span><span class="pln">microsoft</span><span class="pun">-</span><span class="pln">standard</span><span class="pun">-</span><span class="pln">WSL2 </span><span class="com">#1 SMP Wed Dec 16 11:20:35 UTC 2021 x86_64</span> <span class="typ">Shell</span><span class="pun">:</span> <span class="str">/usr/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">zsh PHP binary</span><span class="pun">:</span> <span class="str">/usr/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">php8</span><span class="pun">.</span><span class="lit">1</span><span class="pln"> PHP version</span><span class="pun">:</span> <span class="lit">8.1</span><span class="pun">.</span><span class="lit">0</span><span class="pln"> php</span><span class="pun">.</span><span class="pln">ini used</span><span class="pun">:</span> <span class="str">/etc/</span><span class="pln">php</span><span class="pun">/</span><span class="lit">8.1</span><span class="pun">/</span><span class="pln">cli</span><span class="pun">/</span><span class="pln">php</span><span class="pun">.</span><span class="pln">ini </span><span class="typ">MySQL</span><span class="pln"> binary</span><span class="pun">:</span> <span class="str">/usr/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">mysql </span><span class="typ">MySQL</span><span class="pln"> version</span><span class="pun">:</span><span class="pln"> mysql </span><span class="typ">Ver</span> <span class="lit">8.0</span><span class="pun">.</span><span class="lit">27</span><span class="pun">-</span><span class="lit">0ubuntu0.22</span><span class="pun">.</span><span class="lit">04.1</span> <span class="kwd">for</span> <span class="typ">Linux</span><span class="pln"> on x86_64 </span><span class="pun">((</span><span class="typ">Ubuntu</span><span class="pun">))</span><span class="pln"> SQL modes</span><span class="pun">:</span><span class="pln"> WP</span><span class="pun">-</span><span class="pln">CLI root dir</span><span class="pun">:</span> <span class="str">/home/</span><span class="pln">wp</span><span class="pun">-</span><span class="pln">cli</span><span class="pun">/</span><span class="pln"> WP</span><span class="pun">-</span><span class="pln">CLI vendor dir</span><span class="pun">:</span> <span class="str">/home/</span><span class="pln">wp</span><span class="pun">-</span><span class="pln">cli</span><span class="pun">/</span><span class="pln">vendor WP_CLI phar path</span><span class="pun">:</span><span class="pln"> WP</span><span class="pun">-</span><span class="pln">CLI packages dir</span><span class="pun">:</span> <span class="str">/home/</span><span class="pln">wp</span><span class="pun">-</span><span class="pln">cli</span><span class="pun">/.</span><span class="pln">wp</span><span class="pun">-</span><span class="pln">cli</span><span class="pun">/</span><span class="pln">packages</span><span class="pun">/</span><span class="pln"> WP</span><span class="pun">-</span><span class="pln">CLI </span><span class="kwd">global</span><span class="pln"> config</span><span class="pun">:</span><span class="pln"> WP</span><span class="pun">-</span><span class="pln">CLI project config</span><span class="pun">:</span> <span class="str">/home/</span><span class="pln">wp</span><span class="pun">-</span><span class="pln">cli</span><span class="pun">/</span><span class="pln">wp</span><span class="pun">-</span><span class="pln">cli</span><span class="pun">.</span><span class="pln">yml WP</span><span class="pun">-</span><span class="pln">CLI version</span><span class="pun">:</span> <span class="lit">2.7</span><span class="pun">.</span><span class="lit">1</span>
第 3 步。更新 WP-CLI。
如果有可用的核心更新,您可以使用以下命令更新WordPress安装:
<span class="pln">wp core update</span>
第 4 步。WP-CLI 命令示例。
下表总结了一些 WP-CLI 命令和示例:
WP-CLI 命令 | 例 |
---|---|
wp core download |
wp core download |
wp core install |
wp core install --url=example.com --title="Example Site" --admin_user=admin --admin_password=password --admin_email=admin@example.com |
wp plugin install |
wp plugin install jetpack |
wp theme install |
wp theme install twentytwenty |
wp post create |
wp post create --post_type=page --post_status=publish --post_title="Example Page" --post_content="This is an example page." |
wp user create |
wp user create example_user example@your-domain.com --role=administrator |
wp option update |
wp option update blogdescription "An example WordPress site" |
wp plugin deactivate |
wp plugin deactivate jetpack |
wp theme switch |
wp theme switch twentytwenty |
wp post list |
wp post list --post_type=page --posts_per_page=5 --order=asc |
感谢您使用本教程在 Ubuntu 22.04 LTS Jammy Jellyfish 系统上安装 WordPress 的 WP-CLI 命令行界面。有关其他帮助或有用信息,我们建议您查看官方WP-CLI网站。
<code class=" prettyprinted"></code>