giovanniciriello/laravel-remote

在远程服务器上执行 Artisan 命令

1.0.0 2021-03-10 09:43 UTC

This package is not auto-updated.

Last update: 2024-09-22 00:51:11 UTC


README

针对低于 8.0 版本的 PHP 的分叉

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

此包提供了一个命令,用于在远程服务器上执行 Artisan 命令。

以下是一个示例,该示例将在远程服务器上清除缓存。

php artisan remote cache:clear

安装

您可以通过 composer 安装此包

composer require giovanniciriello/laravel-remote --ignore-platform-reqs

您可以使用以下命令发布配置文件

php artisan vendor:publish --provider="Spatie\Remote\RemoteServiceProvider" --tag="remote-config"

这是已发布配置文件的内容

return [
    /*
     * This host will be used if none is specified
     * when executing the `remote` command.
     */
    'default_host' => 'default',

    /*
     * Here you can define the hosts where the commands should be executed.
     */
    'hosts' => [
        'default' => [
            'host' => env('REMOTE_HOST'),

            'port' => env('REMOTE_PORT', 22),

            'user' => env('REMOTE_USER'),

            /*
             * The package will cd to the given path before executing the given command.
             */
            'path' => env('REMOTE_PATH'),
        ]
    ],
];

用法

要执行远程服务器上的命令,请使用 remote Artisan 命令。您可以将要执行在服务器上的任何 artisan 命令传递给该命令。

以下是一个清除缓存的示例。

php artisan remote cache:clear

执行原始命令

如果您想执行 bash 命令,请使用 --raw 选项。

以下示例将获取服务器上的文件列表。

php artisan remote ls --raw

使用其他主机

您可以在配置文件中定义主机。默认情况下,使用 default 主机。要执行其他主机上的命令,请使用 --host 选项。

php artisan remote cache:clear --host=my-other-host

在远程命令中使用选项

如果您需要在尝试执行的命令中使用标志或选项,您可以整个命令用引号括起来

php artisan remote --raw "ls -a"

测试

composer test

变更日志

请参阅 CHANGELOG 了解最近更改的更多信息。

贡献

请参阅 CONTRIBUTING 了解详细信息。

安全漏洞

请参阅 我们的安全策略 了解如何报告安全漏洞。

鸣谢

许可证

MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。