gwa/wpsh

WordPress 同步命令行工具

维护者

详细信息

github.com/gwa/wpsh

源代码

问题

安装: 22

依赖: 0

建议者: 0

安全: 0

星标: 3

关注者: 2

分支: 0

公开问题: 3

类型:项目

v1.0.1 2016-12-27 06:58 UTC

This package is not auto-updated.

Last update: 2024-09-15 01:35:26 UTC


README

一个用于本地 WordPress 开发的命令行工具。

简介

wpsh 是一个命令行工具,我们用它从远程(生产)WordPress 安装同步数据库和上传文件到本地(开发)安装。

它受到了 Drupal 的 drush 工具的启发。

先决条件

您需要

  • composer 需要在本地安装(用于安装)。
  • mysql 需要在远程安装。
  • mysqlrsync 需要在本地安装并在您的路径中。
  • 远程服务器的 SSH 访问权限。

安装

使用 composer 全局安装。

$ composer global require gwa/wpsh

测试 wpsh 是否已安装

$ wpsh

您应该看到一些使用帮助输出。

设置

别名

站点 "别名" 包含站点的配置,无论是远程还是本地。 wpsh~/.wpsh 中查找站点别名。

首先在您的 HOME 目录中创建该目录。

$ mkdir ~/.wpsh

~/.wpsh 中创建一个名为 alias.[mysite].php 的文件。

mysite 可以包含字母数字字符、连字符和点。

<?php
// File: ~/.wpsh/alias.mysite.php
return [
  // The production server
  //
  '@mysite.prod' => [
    // SSH configuration
    'remote' => [
      'host'     => '123.255.12.123',
      'user'     => 'username',
      // Path to a SSH key file
      // 'identity' => '~/.ssh/custom_rsa',
    ],

    // Absolute paths
    'path' => [
      // The base directory
      'base'    => '/var/www/mysite',
      // Path to a custom MySQL cnf file
      'cnf'     => '~/mysql_cnf/mysite.cnf',
      // Path to a custom wp dir, relative to base
      // 'wp' => '',
      // Path to a custom uploads dir, relative to base
      // 'uploads' => 'wp-content/uploads',
    ],

    // Database settings
    'db' => [
      // Name of the database
      'database' => 'dbname'
    ],

    // Other settings
    'settings' => [
      'siteurl' => 'http://www.example.com',
      // Set a custom `home` path. Defaults to siteurl.
      // 'home' => 'http://www.example.com/wp',
    ]
  ],

  // The local development copy
  // Settings as above, but without `remote`
  //
  '@mysite.local' => [
    'path' => [
      'base'    => '/path/local/server/wordpress',
    ],

    'db' => [
      'database' => 'dbname',
    ],

    'settings' => [
      'siteurl' => 'http://mysite.local',
    ]
  ],
];

MySQL cnf 文件

我们使用 cnf 文件 来存储 MySQL 凭据

您可以将这些文件保存在默认路径之一(参见 MySQL 文档),或者保存在站点别名定义的 cnf 路径中的自定义路径。

示例

[client]
user=mysqluser
password="pa$$word"
host=127.0.0.1
port=3306

用法

以下命令可用。

sa

列出可用的别名。

$ wpsh sa

mysqldump

创建 mysql 导出文件。

$ wpsh mysqldump [@alias] > /path/to/outfile.sql

mysqlsync

从 @alias1 同步 DB 到 @alias2。

更新文章中的设置和 URL,使用本地设置和 URL。

$ wpsh mysqlsync [@alias1] [@alias2]

rsync

从 @alias1 同步上传到 @alias2。

$ wpsh rsync [@alias1] [@alias2]

待办事项

[ ] 提供钩子机制,以在同步后执行自定义脚本/MySQL 查询。