mcpField
W
wp-wpengine

wp-wpengine

github.com/kylebrodeur云与 DevOps149 次安装1 周前更新
代码仓库

关于 wp-wpengine

介绍通过 SSH、WP-CLI 和部署工作流向 WP Engine 部署 WordPress 代码并管理安装环境的技能指南,涵盖 GitHub Actions、git push、远程运维和用量报告。

主要功能

  1. 01通过 GitHub Actions 部署
  2. 02通过 git push 部署
  3. 03远程运行 WP-CLI
  4. 04SSH 与文件传输指引
  5. 05管理安装、域名、缓存、备份和用户
  6. 06生成用量与带宽报告

适用场景

  1. 01向不同环境部署 WordPress 变更
  2. 02远程更新插件或清理缓存
  3. 03使用 search-replace 迁移域名
  4. 04准备月度账户用量报告

MCP 相关

指南提到可借助 `wpe-labs` Claude Code skills 通过自然语言管理 WP Engine 安装及相关操作;未描述 MCP 服务。

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/kylebrodeur/wordpress-agent-kit --skill wp-wpengine

安装后在 Claude Code 中输入/wp-wpengine确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
ci-gate.md
github-actions-deploy.md
scripts/
ci-gate.sh
wpe-check.sh
wpe-preflight.sh

详细介绍

WP Engine

适用场景

  • 通过 git push 或 GitHub Actions 将 WordPress 代码部署到 WP Engine 环境。
  • 设置按分支控制的 CI/CD 流水线:develop → 开发环境,staging → 预发布环境,main → 生产环境。
  • 在 WP Engine 安装上远程运行 WP-CLI 命令(插件更新、清除缓存、数据库操作、搜索替换)。
  • 通过自然语言管理 WP Engine 安装、域名、缓存、备份或用户。
  • 生成涵盖多个 WP Engine 账户的月度用量/带宽报告。
  • 管理 LargeFS 媒体卸载配置。

前提条件

  • SSH 密钥存储在 1Password 中(Employee 保管库,条目 wpengine_ed25519)。

    密钥类型说明: RSA 4096 位是经过长期验证、适用于 WP Engine git push 的密钥类型。 Ed25519 更新一些,且可在当前 WP Engine 基础设施上使用;但如果要设置新密钥, RSA 4096 是最稳妥的选择:ssh-keygen -t rsa -b 4096 -f ~/.ssh/wpengine_rsa

  • SSH 密钥已在 WP Engine 门户中注册——分别在 Git Push 和 SSH Keys 下注册(两个独立注册,使用同一个密钥)。
  • WP Engine API 凭据存储在 1Password 中(Employee 保管库,条目 WP Engine API)。
  • op CLI 已通过身份验证(op whoami 可正常运行)。
  • SSH 网关访问需要 Professional 计划或更高版本。
  • 已安装 wpe-labs Claude Code 技能(~/.claude/skills/wpe-labs:*),以便通过自然语言进行管理。

操作步骤

1) 在新机器上首次设置 SSH

从 1Password 获取私钥并配置 SSH:

op read "op://Employee/wpengine_ed25519/private key" > ~/.ssh/wpengine_ed25519
chmod 600 ~/.ssh/wpengine_ed25519

# Trust WP Engine git push host (RSA — what WP Engine's git.wpengine.com serves)
ssh-keyscan -t rsa git.wpengine.com >> ~/.ssh/known_hosts
# Gateway: scan the specific install hostname (each install has its own subdomain)
# Do this once per environment you connect to:
ssh-keyscan -H <install>.ssh.wpengine.net >> ~/.ssh/known_hosts
# e.g.: ssh-keyscan -H mysite.ssh.wpengine.net >> ~/.ssh/known_hosts

将以下内容添加到 ~/.ssh/config(放在任何 Host * 块之前):

# WP Engine git push
Host git.wpengine.com
  User git
  IdentityFile ~/.ssh/wpengine_ed25519
  IdentitiesOnly yes

# WP Engine SSH gateway (WP-CLI + file transfer)
Host *.ssh.wpengine.net
  IdentityFile ~/.ssh/wpengine_ed25519
  IdentitiesOnly yes
  ControlMaster auto
  ControlPath ~/.ssh/wpe-%r@%h:%p
  ControlPersist 10m
  StrictHostKeyChecking accept-new

StrictHostKeyChecking accept-new:首次连接时自动接受并存储主机密钥,之后若密钥发生变化则拒绝连接(防止中间人攻击)。比 no 更安全;无需为每个安装主机名手动运行 ssh-keyscan。

ControlMaster / ControlPersist:复用 SSH 连接,使后续通过同一网关执行的命令能够使用现有连接。对于重复调用 WP-CLI 的情况,可将每条命令的延迟从约 2 秒降至约 100 毫秒。

验证 git push 访问权限:

ssh [email protected] info
# Expected: hello <username> / R W <install-name>

验证 SSH 网关访问权限(将 <install> 替换为 WP Engine 安装的 slug):

ssh <install>@<install>.ssh.wpengine.net wp --info
# Expected: WP-CLI version + paths

2A) 通过官方 WP Engine GitHub Action 部署(推荐)

官方 WP Engine GitHub Action 使用 通过 SSH 的 rsync——比 git push 更快、更灵活,并由 WP Engine 构建和维护。

仓库:wpengine/github-action-wpe-site-deploy@v3

必需的密钥

官方 Action 使用 WPE_SSHG_KEY_PRIVATE(你的 SSH 私钥)。该 Action 会自动处理 known_hosts,无需运行 keyscan。

# .github/workflows/deploy-production.yml
name: Deploy → Production
on:
  push:
    branches: [main]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Build assets
        run: npm ci && npm run build

      - name: Deploy to WP Engine
        uses: wpengine/github-action-wpe-site-deploy@v3
        with:
          WPE_SSHG_KEY_PRIVATE: ${{ secrets.WPE_SSHG_KEY_PRIVATE }}
          WPE_ENV: <install-name>
          PHP_LINT: true
          CACHE_CLEAR: true
          # Optional: deploy only a subdirectory (e.g., a theme)
          # SRC_PATH: "wp-content/themes/my-theme/"
          # REMOTE_PATH: "wp-content/themes/my-theme/"
          # Exclude files via rsync flags:
          FLAGS: -azvr --inplace --delete --exclude=.* --exclude-from=.deployignore
          # Post-deploy WP-CLI script (runs on the remote server):
          SCRIPT: "scripts/post-deploy.sh"

scripts/post-deploy.sh(提交到仓库,在部署后于 WP Engine 上运行):

#!/usr/bin/env bash
set -e
wp cache flush --skip-plugins --skip-themes
wp rewrite flush --skip-plugins --skip-themes
wp cron event run --due-now --skip-plugins --skip-themes
echo "✅ Post-deploy WP-CLI complete"

.deployignore(rsync 排除列表,提交到仓库根目录):

.git
node_modules
.env
.env.*
README.md
.github
package.json
package-lock.json
pnpm-lock.yaml
composer.json
composer.lock
*.test.*
tests/

关键选项:

选项说明
WPE_ENV安装 slug。别名:多环境工作流可使用 PRD_ENV、STG_ENV、DEV_ENV
SRC_PATH要部署的仓库子目录(末尾带斜杠 = 仅部署目录内容)
REMOTE_PATHWP Engine 上的目标路径(默认为 WordPress 根目录)
PHP_LINT设为 true 可在部署前运行 PHP lint
FLAGSrsync 标志。默认值:-azvr --inplace --exclude=.*
SCRIPT部署后运行的 bash 脚本(服务器上相对于 WordPress 根目录的路径)
CACHE_CLEAR设为 true 可在部署后清除页面和 CDN 缓存(默认值:true)

多环境工作流:

# Branch → environment mapping
on:
  push:
    branches: [develop, staging, main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm run build
      - uses: wpengine/github-action-wpe-site-deploy@v3
        with:
          WPE_SSHG_KEY_PRIVATE: ${{ secrets.WPE_SSHG_KEY_PRIVATE }}
          # Branch → env: develop=dev, staging=stg, main=prod
          DEV_ENV: ${{ github.ref == 'refs/heads/develop' && '<install>dev' || '' }}
          STG_ENV: ${{ github.ref == 'refs/heads/staging' && '<install>stg' || '' }}
          PRD_ENV: ${{ github.ref == 'refs/heads/main' && '<install>' || '' }}
          CACHE_CLEAR: true

密钥名称差异:官方 Action 使用 WPE_SSHG_KEY_PRIVATE。我们的自定义 git-push 工作流使用 WPE_SSH_KEY。两者是同一个私钥,只是存储时使用了不同的密钥名称。


2B)通过 git push 部署(替代方式)

务必从 WP Engine 门户获取准确的远程 URL——其中包含环境前缀: https://my.wpengine.com/installs/<ENV>/git_push

URL 格式为:[email protected]:<environment>/<install-name>.git
其中 <environment> 可以是 production、staging 或 development。

# Production (copy exact URL from portal)
# ⚠️  Always copy the exact URL from the WP Engine portal — formats vary by account:
#    https://my.wpengine.com/installs/<ENV>/git_push
#
# Modern accounts (most common):
git remote add wpengine-prod [email protected]:<install-name>.git
# Legacy accounts (some plans add an environment prefix):
# git remote add wpengine-prod [email protected]:production/<install-name>.git

# Staging (check portal for exact URL)
git remote add wpengine-staging [email protected]:<install-name>stg.git

# Development (check portal for exact URL)
git remote add wpengine-dev [email protected]:<install-name>dev.git

部署:

git push wpengine-prod main
# WP Engine expects the branch name 'main' on its remote
git push wpengine-staging staging:main
  • WP Engine 会自动部署推送的分支。
  • 只会推送 WordPress 文件,不会推送 node_modules、构建产物或 .git/。
  • 推送后,请等待 1–2 分钟以完成同步。

验证远程 URL:git remote -v 应显示 [email protected]:production/<install>.git。 如果显示的是 [email protected]:<install>.git(没有环境前缀),请更新它——这是较旧的格式,可能已无法使用。


3)通过 SSH 网关使用 WP-CLI

WP Engine 的 SSH 网关主机为 {install}.ssh.wpengine.net,用户名为 {install}。
服务器上的 WordPress 根目录为 /home/wpe-user/sites/{install}。

方法 A — 直接运行 SSH 命令(最简单)
ssh <install>@<install>.ssh.wpengine.net wp <command>

WP Engine 上的 WP-CLI 已知晓 WordPress 路径,因此通常不需要 --path。如有需要:

ssh <install>@<install>.ssh.wpengine.net wp plugin list --path=/home/wpe-user/sites/<install>

为确保安全,在生产环境中始终使用 --skip-plugins --skip-themes:

ssh <install>@<install>.ssh.wpengine.net \
  wp cache flush --skip-plugins --skip-themes
方法 B — WP-CLI 的 --ssh 标志

WP-CLI 原生的 --ssh 标志可以在无需先登录的情况下,对远程安装运行任何命令:

# Format: --ssh=user@host/path
wp --ssh=<install>@<install>.ssh.wpengine.net:/home/wpe-user/sites/<install> plugin list

# Shorthand — omit path if WP-CLI finds WP at the SSH user's home:
wp --ssh=<install>@<install>.ssh.wpengine.net cache flush
方法 C — wp-cli.yml 别名(适合重复使用)

在本地仓库根目录中创建或更新 wp-cli.yml:

# wp-cli.yml
@production:
  ssh: <install>@<install>.ssh.wpengine.net
  path: /home/wpe-user/sites/<install>

@staging:
  ssh: <install>stg@<install>stg.ssh.wpengine.net
  path: /home/wpe-user/sites/<install>stg

然后使用别名运行任何命令:

wp @production plugin list --format=json
wp @staging cache flush
wp @production db export - > backup-$(date +%F).sql
wp @production search-replace 'old-domain.com' 'new-domain.com' --dry-run

将 wp-cli.yml 提交到仓库,以便所有团队成员和 CI 流水线共用相同的远程别名。

方法 D — 使用 SCP / rsync 传输文件

SSH 网关也支持 SCP 和 rsync(端口 22)。无需完整的 git push,即可使用它们拉取或推送文件:

# SCP: download a file from the server
scp -P 22 <install>@<install>.ssh.wpengine.net:sites/<install>/wp-content/uploads/large-file.zip ./

# SCP: upload a file to the server
scp -P 22 ./my-patch.php <install>@<install>.ssh.wpengine.net:sites/<install>/wp-content/plugins/my-plugin/

# rsync: sync wp-content/uploads from production to local (read-only pull)
rsync -avz --progress \
  -e "ssh -p 22" \
  <install>@<install>.ssh.wpengine.net:sites/<install>/wp-content/uploads/ \
  ./local-uploads/

# rsync: push a theme to staging (careful with --delete)
rsync -avz --dry-run \
  -e "ssh -p 22" \
  ./my-theme/ \
  <install>stg@<install>stg.ssh.wpengine.net:sites/<install>stg/wp-content/themes/my-theme/

WP Engine 服务器路径:相对于 SSH 主目录,WordPress 根目录为 sites/<install>/;绝对路径为 /home/wpe-user/sites/<install>。wp-content/ 位于该根目录中。

方法 E — 通过 heredoc 运行多条命令

在一个 SSH 会话中运行多条命令,无需重新连接:

# Heredoc over SSH (most efficient — one connection for all commands)
ssh <install>@<install>.ssh.wpengine.net bash -s << 'EOF'
  set -e
  wp cache flush --skip-plugins --skip-themes
  wp rewrite flush --skip-plugins --skip-themes
  wp cron event run --due-now --skip-plugins --skip-themes
  wp core version --skip-plugins --skip-themes
EOF

# Interactive WP-CLI commands need -t (pseudo-TTY allocation)
# e.g. wp shell for a REPL session
ssh -t <install>@<install>.ssh.wpengine.net wp shell
SSH 网关环境说明
  • 受限 shell:网关提供受限的 shell 环境。可使用 WP-CLI、PHP、基本 POSIX 实用程序(echo、cat、stat、du、find、grep)以及 rsync/SCP。不支持安装软件包(apt、yum)、sudo 和任意服务管理。
  • PHP 版本:与该 WP Engine 安装所配置的 PHP 版本一致。运行 php --version 进行确认。
  • WordPress 路径:~/sites/<install>/(相对于 SSH 主目录)或 /home/wpe-user/sites/<install>(绝对路径)。
  • --path 标志:如果 WP-CLI 返回“not a WordPress installation”,请显式添加 --path=/home/wpe-user/sites/<install>。
  • 旧版网关:ssh.wpengine.net(没有子域名)是旧的通用网关地址。当前约定始终使用 <install>.ssh.wpengine.net。

4)常见的远程 WP-CLI 操作

务必先运行 --dry-run 或进行只读检查。以下示例均使用方法 C 的别名。

检查环境
wp @production cli info
wp @production option get siteurl
wp @production option get home
wp @production core version
插件和主题管理
# List all plugins with status
wp @production plugin list --format=json

# Update a specific plugin
wp @production plugin update woocommerce

# Update all plugins (preview first)
wp @production plugin update --all --dry-run
wp @production plugin update --all

# Activate/deactivate
wp @production plugin activate <slug>
wp @production plugin deactivate <slug> --skip-plugins --skip-themes
清除缓存(部署后始终安全)
wp @production cache flush
wp @production rewrite flush
wp @production transient delete --all
数据库操作
# Export to local file (streams via SSH)
wp @production db export - > backup-$(date +%F-%H%M).sql

# Check DB size
wp @production db size --tables --format=table

# Run a specific query
wp @production db query "SELECT option_name, option_value FROM wp_options WHERE autoload='yes' LIMIT 20"
搜索和替换(迁移 / 域名更改)
# Always dry-run first
wp @production search-replace 'http://old-domain.com' 'https://new-domain.com' \
  --dry-run --report-changed-only

# Then apply (--precise handles serialized data safely)
wp @production search-replace 'http://old-domain.com' 'https://new-domain.com' \
  --precise --report-changed-only

# Flush after replace
wp @production cache flush && wp @production rewrite flush

完整的搜索和替换模式请参阅 wp-wpcli-and-ops 技能 → references/search-replace.md。

用户管理
# List admin users
wp @production user list --role=administrator --format=table

# Create a temporary admin (disable after)
wp @production user create tempagent [email protected] --role=administrator --user_pass=<strong-pass>
# ... do work ...
wp @production user delete tempagent --reassign=1
Cron 检查和触发
wp @production cron event list --format=table
wp @production cron event run --due-now
wp @production cron event run <hook-name>

5)远程数据库访问

WP Engine 提供三种访问远程数据库的方式。无需将 IP 地址加入允许列表。

方法 A — 通过 SSH 网关运行 wp db query(最简单,推荐)

无需额外工具或凭据——通过经过身份验证的 SSH 隧道连接:

# Interactive query
ssh <install>@<install>.ssh.wpengine.net wp db query 'SELECT post_title FROM wp_posts LIMIT 10;'

# Export full DB (streams to local file)
ssh <install>@<install>.ssh.wpengine.net wp db export - > backup-$(date +%F).sql

# Or via wp-cli.yml alias
wp @production db export - > backup-$(date +%F).sql
wp @production db query 'SELECT option_name, option_value FROM wp_options WHERE autoload="yes" LIMIT 20;'
方法 B — SSH 隧道 + GUI 工具(MySQL Workbench、Sequel Ace、TablePlus)

首先从服务器获取 DB 密码:

# Get DB password from wp-config.php
ssh <install>@<install>.ssh.wpengine.net \
  wp config get DB_PASSWORD --skip-plugins --skip-themes

# Or from the private config file
ssh <install>@<install>.ssh.wpengine.net \
  "grep WPENGINE_SESSION_DB_PASSWORD ./sites/<install>/_wpeprivate/config.json"

使用本地端口转发启动 SSH 隧道:

ssh -L 3307:127.0.0.1:3306 <install>@<install>.ssh.wpengine.net
# Keep this terminal open while using your GUI tool

使用以下信息连接 GUI 工具:

字段值
连接方式通过 SSH 使用 TCP/IP(或隧道开启后使用普通 TCP)
SSH 主机名<install>.ssh.wpengine.net
SSH 用户名<install>
SSH 密钥文件~/.ssh/wpengine_ed25519
MySQL 主机127.0.0.1
MySQL 端口3306(Workbench/Sequel Ace)或 3307(通过隧道使用的其他工具)
数据库用户名<install>
数据库密码来自 DB_PASSWORD / WPENGINE_SESSION_DB_PASSWORD
数据库名称wp_<install>

MySQL Workbench:使用 Standard (TCP/IP) over SSH 连接类型——它会在内部处理隧道,无需单独运行 ssh -L。 Sequel Ace:使用 SSH 连接类型。如果连接超时,请在 Network 设置中将超时时间增加到 60s。 TablePlus、DBeaver、DataGrip:手动开启 ssh -L 3307:... 隧道后,使用 TCP 模式。

服务器上的 DB 凭据位置
# From wp-config.php
ssh <install>@<install>.ssh.wpengine.net grep "DB_" sites/<install>/wp-config.php

# From WP Engine private config (includes session password)
ssh <install>@<install>.ssh.wpengine.net cat sites/<install>/_wpeprivate/config.json

DB 名称格式:wp_<install>(例如 wp_mysite)。config.json 中名为 WPENGINE_SESSION_DB_PASSWORD 的会话密码可能会轮换——如需持久访问,请优先使用 wp-config.php 中的 DB_PASSWORD。


6) 将 WP Engine 环境拉取到本地 Playground

用于本地开发的完整 DB + 搜索替换工作流:

# 1. Export DB from WP Engine dev
wp @development db export - > /tmp/wpe-dev-$(date +%F).sql

# 2. Import into local WordPress
wp db import /tmp/wpe-dev-$(date +%F).sql

# 3. Search-replace remote domain with local
wp search-replace 'https://dev.yoursite.wpengine.com' 'http://localhost:9400' \
  --precise --report-changed-only

# 4. Flush caches
wp cache flush && wp rewrite flush

# 5. Remote media — set upload_url_path so images load from the live server
#    (no rsync of wp-content/uploads needed)
wp option update upload_url_path 'https://dev.yoursite.wpengine.com/wp-content/uploads'
# Images and attachments now load from the remote server transparently.
# To revert when done:  wp option delete upload_url_path

upload_url_path:WordPress 选项(wp_options),用于覆盖所有上传媒体的基准 URL。将它设置为远程服务器的 uploads 路径后,本地 WordPress 就能从生产/暂存环境加载真实图片,无需同步任何文件。对于 GB 级媒体,这比 rsync 快得多。部署前使用 wp option delete upload_url_path 重置。

部分同步替代方案:如果你已将一些近期上传的文件复制到本地(例如为了重新生成图片尺寸),但希望较早月份的文件仍从生产环境加载,请改用 BE Media from Production。它会按日期范围筛选图片 URL,而不是重定向所有图片。完全没有本地上传文件时,upload_url_path 更简单,也很实用。

如需同时同步实际上传文件(当你需要在本地访问文件,而不只是访问 URL 时):

# rsync uploads from WP Engine (large — use --dry-run first)
rsync -avz --dry-run \
  -e "ssh -p 22" \
  [email protected]:sites/myinstall/wp-content/uploads/ \
  ./wp-content/uploads/

完整的自动化版本请参阅 wp-bootstrap skill → scripts/pull-wpe-env.sh。


如需使用分支门控进行完整部署,并启用安全防护、部署前备份、冒烟测试和自动回滚:

阅读:references/github-actions-deploy.md

CI 门控策略——禁止使用 --no-verify:

  • 所有 lint、类型检查、测试和构建检查都必须通过,才能将任何推送合并到部署分支。
  • 明确禁止使用 --no-verify。钩子的作用是及早发现问题——绕过它们,故障就由你负责。
  • 每次向受保护分支推送时,CI 门控都会运行两个并行任务(php-gate + js-gate)。这是必需的状态检查。
  • 每个部署工作流都会将 verify 任务作为第一个依赖项——只有该任务通过后,部署才会开始。

阅读:references/ci-gate.md

可由 Agent 运行的脚本:

脚本用途使用时机
scripts/ci-gate.sh运行完整的本地 CI 门控(PHP + JS/TS)向部署分支推送前
scripts/wpe-preflight.sh部署前健全性检查(SSH、WP、HTTP)触发部署前
scripts/wpe-check.sh检查所有已配置安装的 SSH 连通性机器设置后或调试 SSH 时

在本地运行 CI 门控:

bash {baseDir}/scripts/ci-gate.sh

运行部署前检查:

INSTALL=mysite bash {baseDir}/scripts/wpe-preflight.sh production

检查所有 SSH 连接:

bash {baseDir}/scripts/wpe-check.sh

10)wpe-labs 技能(自然语言管理)

加载 API 凭据,然后使用任意 /wpe-labs:* 技能:

# Load credentials from 1Password for the session
eval $(op run --env-file ~/.config/op-ssh/.env.1pass -- env | grep ^WPE | sed 's/^/export /')
技能功能风险
/wpe-labs:account-usage查看各账户的带宽、访问量和存储空间🟢 只读
/wpe-labs:monthly-report生成可供客户端使用的月度用量报告🟢 只读
/wpe-labs:backups按需备份 + 进度监控🟡 写入
/wpe-labs:cache清除对象缓存/页面缓存/CDN 缓存🟡 写入
/wpe-labs:users列出、邀请、更新角色、移除用户🟡/🔴
/wpe-labs:domains管理域名、DNS、SSL🟡/🔴
/wpe-labs:installs列出、创建、复制 WordPress 安装🟡/🔴
/wpe-labs:offloadLargeFS 媒体卸载配置🟡 写入

示例提示词:

/wpe-labs:account-usage which accounts are closest to their bandwidth limit?
/wpe-labs:cache purge all cache for uofdev production
/wpe-labs:backups back up uofdev production before deployment
/wpe-labs:installs copy uofdev production to staging
/wpe-labs:monthly-report last month
11)重新安装 wpe-labs 技能
curl -fsSL https://raw.githubusercontent.com/wpengine/wpe-labs-platform-skills/main/install.sh | bash

验证

检查项命令
Git 推送 SSHssh [email protected] info → hello <user> / R W <install>
SSH 网关ssh <install>@<install>.ssh.wpengine.net wp --info
WP-CLI 别名wp @production core version
API 凭据`op run --env-file ~/.config/op-ssh/.env.1pass -- bash -c 'curl -s -u "$WPE_USERNAME:$WPE_PASSWORD" https://api.wpengineapi.com/v1/user

远程操作安全防护措施

  • 对任何搜索替换或破坏性数据库操作,务必先使用 --dry-run。
  • 修改架构或进行大规模搜索替换前,务必导出数据库备份。
  • 在生产环境中执行缓存清理、停用操作,以及任何可能因插件故障而中断的操作时,使用 --skip-plugins --skip-themes。
  • 在生产环境运行 WP-CLI 命令前,优先在暂存环境中测试。
  • ControlMaster 是安全的——它会重复使用现有的已认证会话;不会存储新的凭据。
  • 执行 wpe-labs 写入操作(backups、cache、installs、users、domains)前,应先确认。

故障模式

症状解决方法
Host key verification failed(git)ssh-keyscan git.wpengine.com >> ~/.ssh/known_hosts
Host key verification failed(网关)针对该安装对应的主机名运行 ssh-keyscan -H <install>.ssh.wpengine.net >> ~/.ssh/known_hosts。或者,将 StrictHostKeyChecking accept-new 添加到 *.ssh.wpengine.net SSH 配置块中——首次连接时会自动接受。
Permission denied确认密钥位于 ~/.ssh/wpengine_ed25519,并运行 chmod 600。检查该密钥是否已在 WP Engine 门户的 SSH Keys 中注册(与 git 推送密钥分开)。
git push rejected从门户获取准确的 URL(https://my.wpengine.com/installs/<ENV>/git_push)。URL 格式因账户而异——请原样复制。
SSH 网关挂起终止过期的 ControlMaster 套接字:ssh -O stop <install>@<install>.ssh.wpengine.net
网关上出现 wp: command not foundWP Engine 的 WP-CLI 路径:尝试 php /usr/local/bin/wp,或联系 WP Engine 支持
WP-CLI 返回错误站点明确添加 --path=/home/wpe-user/sites/<install>
401 Unauthorized(wpe-labs)在 https://my.wpengine.com/api_access 重新生成 API 凭据,并更新 1Password 条目
storage shows zero(wpe-labs)请求“刷新存储空间”(异步重新计算,约需 30–60 秒)

参考资料

  • WP Engine SSH 网关文档:https://wpengine.com/support/ssh-gateway/
  • WP Engine git 推送门户:https://my.wpengine.com/installs/<ENV>/git_push
  • WP Engine SSH Keys 门户:https://my.wpengine.com/ssh_keys
  • WP Engine API 访问:https://my.wpengine.com/api_access
  • WP-CLI --ssh 文档:https://make.wordpress.org/cli/handbook/guides/running-commands-remotely/
  • wpe-labs 技能源代码:https://github.com/wpengine/wpe-labs-platform-skills
  • SSH 设置日志(第一台机器):gist 602d6a16ddfea438c0611a8e5cc31d5e

评论

支持 Markdown