Execute Artisan commands on remote servers

Overview

Execute Artisan commands on remote servers

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

This package provides a command to execute Artisan command on a remote server.

Here's an example that will clear the cache on the remote server.

php artisan remote cache:clear

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/laravel-remote

You can publish the config file with:

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

This is the contents of the published config file:

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'),
        ]
    ],
];

Usage

To execute a command on the remote server use the remote Artisan command. You can pass any artisan command that you would like to execute on the server.

Here's an example where we clear the cache.

php artisan remote cache:clear

Executing raw commands

If you want to execute a bash command, use the --raw option.

Here we will get a list of files on the server.

php artisan remote ls --raw

Using another host

You can define hosts in the config file. By default, the default host is used. To execute a command on another host use the --host option.

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

Using options in remote commands

If you need to use flags or options in the command you're trying to execue, you can wrap the entire command in quotes:

php artisan remote --raw "ls -a"

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments
  • PHP 7.4 support

    PHP 7.4 support

    is it possible to support at least latest version of php 7.4?

    https://github.com/spatie/laravel-remote/blob/add355f8becdad72e0ffc068bfa473c1a520e859/composer.json#L18

    opened by CaddyDz 3
  • Added confirmation prompt

    Added confirmation prompt

    A confirmation prompt may be useful to prevent the execution of sensitive Laravel artisan commands.

    I am making the pull request after suggestion on this tweet, cheers. https://twitter.com/abdelkader_mh/status/1535212593098399745

    image

    opened by AbdelkaderBah 2
  • feature/run-command-on-multiple-servers

    feature/run-command-on-multiple-servers

    Changes:

    • Added support for running multiple servers at once
    • Added tags for grouping servers to be run together.
    • Default host config parameters
    • Minor refactor of RemoteCommand class

    I think everything should be backwards compatible.

    TODO

    • [ ] Update Readme

    What do you think?

    opened by pelmered 2
  • Only show single line of output when using --raw

    Only show single line of output when using --raw

    Hi, Thanks for the great package as always 🙏

    When I use --raw to list files for example or do any other command, it only shows the first line of output.

    Screen Shot 2021-03-22 at 2 09 01 AM

    While if I logged in using ssh on the same remote server I got everything : Screen Shot 2021-03-22 at 2 11 49 AM

    bug good first issue help wanted 
    opened by onemoreahmad 2
  • feat: Allow ANSI on `artisan` calls to match local artisan.

    feat: Allow ANSI on `artisan` calls to match local artisan.

    This PR adds the capability to receive the artisan output with colors.

    It also set the width to be the same as the current terminal, and add \n before and after the call to match the local artisan output.

    Local

    image

    Remote Before

    image

    Remote After

    image
    opened by xiCO2k 1
  • fix: Allow dots on hosts

    fix: Allow dots on hosts

    This PR fix an issue when using dots on an host due to the config("remote.hosts.{$hostName}").

    Example

    // config/remote.php
    
        'hosts' => [
            'example.com' => [
                'host' => 'example.com',
                'port' => env('REMOTE_PORT', 22),
                'user' => env('REMOTE_USER'),
            ]
        ],
    
    opened by xiCO2k 1
  • minor improvements

    minor improvements

    This PR:

    • adds expectations on the Exceptions messages
    • removes additional blank lines
    • adds more type information on the method's parameters
    • fixes wrong exception message when a required config value is not set
    opened by chapeupreto 1
Releases(1.3.2)
  • 1.3.2(Oct 27, 2022)

    What's Changed

    • feat: Allow ANSI on artisan calls to match local artisan. by @xiCO2k in https://github.com/spatie/laravel-remote/pull/20
    • PHP 8.2 Build by @sergiy-petrov in https://github.com/spatie/laravel-remote/pull/19
    • fix: Allow dots on hosts by @xiCO2k in https://github.com/spatie/laravel-remote/pull/18

    New Contributors

    • @xiCO2k made their first contribution in https://github.com/spatie/laravel-remote/pull/20
    • @sergiy-petrov made their first contribution in https://github.com/spatie/laravel-remote/pull/19

    Full Changelog: https://github.com/spatie/laravel-remote/compare/1.3.1...1.3.2

    Source code(tar.gz)
    Source code(zip)
  • 1.3.1(Oct 26, 2022)

    What's Changed

    • Update Readme about private_key_path config by @ziming in https://github.com/spatie/laravel-remote/pull/17

    Full Changelog: https://github.com/spatie/laravel-remote/compare/1.3.0...1.3.1

    Source code(tar.gz)
    Source code(zip)
  • 1.3.0(Oct 7, 2022)

    What's Changed

    • Update .gitattributes by @angeljqv in https://github.com/spatie/laravel-remote/pull/14
    • Fix a small typo by @rafa1944 in https://github.com/spatie/laravel-remote/pull/15
    • Allow private key to be specified by @ziming in https://github.com/spatie/laravel-remote/pull/16

    New Contributors

    • @angeljqv made their first contribution in https://github.com/spatie/laravel-remote/pull/14
    • @rafa1944 made their first contribution in https://github.com/spatie/laravel-remote/pull/15
    • @ziming made their first contribution in https://github.com/spatie/laravel-remote/pull/16

    Full Changelog: https://github.com/spatie/laravel-remote/compare/1.2.0...1.3.0

    Source code(tar.gz)
    Source code(zip)
  • 1.2.0(Jun 10, 2022)

    What's Changed

    • Added confirmation prompt by @AbdelkaderBah in https://github.com/spatie/laravel-remote/pull/13

    New Contributors

    • @AbdelkaderBah made their first contribution in https://github.com/spatie/laravel-remote/pull/13

    Full Changelog: https://github.com/spatie/laravel-remote/compare/1.1.0...1.2.0

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Jan 19, 2022)

  • 1.0.2(Apr 1, 2021)

  • 1.0.1(Mar 29, 2021)

  • 1.0.0(Mar 10, 2021)

  • 0.0.2(Mar 9, 2021)

  • 0.0.1(Mar 9, 2021)

Owner
Spatie
We create products and courses for the developer community
Spatie
Refresh artisan commands,table,migrations,models,controllers...

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Javier Fernández 11 Oct 18, 2022
A Laravel 9 package that allows you enforce security of your artisan commands by authenticating users before running.

Introduction This package allows you as a developer to restrict who can and cannot run artisan commands, especially in a production environment. For e

YOo Slim 2 Sep 15, 2022
The swiss army knife for Magento developers, sysadmins and devops. The tool provides a huge set of well tested command line commands which save hours of work time. All commands are extendable by a module API.

netz98 magerun CLI tools for Magento 2 The n98 magerun cli tools provides some handy tools to work with Magento from command line. Build Status Latest

netz98 758 Dec 28, 2022
Execute time consuming tasks as late as possible in a request

Procrastinator for PHP: do stuff later A few classes to help you executing complicated tasks (like sending mails) later. Example using fastcgi_finish_

Lars Strojny 62 Apr 29, 2021
Quickly execute Composer package binaries from anywhere. ⚡️

✨ Help support the maintenance of this package by sponsoring me. cpx Quickly execute Composer package binaries from anywhere. ⚡️ Installation Run the

Ryan Chandler 57 Dec 25, 2022
Comprehensive Plugin for composer to execute PHP Quality assurance Tools

NOT MAINTANED ANYMORE The development of composer-plugin-qa was dropped in favor of phpqa which is actively maintained. The project use docker and can

Webysther Nunes 25 Apr 30, 2021
Install an execute script of specify quality tools to your git pre-commit hook, and it executes only for changed files

Quality Hook Installer Install an execute script of specify quality tools to your git pre-commit hook, and it executes only for changed files Install

Kay W. 2 Dec 15, 2022
The plugin allows to execute math operations in the server or console.

General The plugin allows to execute math operations in the server or console with /calculator command Arithmetic Operators List of supported arithmet

NhanAZ's PocketMine-MP Plugins 3 Oct 20, 2022
PHP remote closure executor

Jumper Allow you to execute PHP Closure in other distant computer via SSH and without client/server setup. Source computer dependency: PHP >= 5.3 (so

Thibaud Lepretre 45 Aug 11, 2022
Rafel is Remote Access Tool Used to Control Victims Using WebPanel With More Advance Features..

Rafel is Remote Access Tool Used to Control Victims Using WebPanel With More Advance Features..

swagkarna 690 Dec 28, 2022
Remote Git Library for PHP

This library provides methods to handle git repositories remotely without having to clone the whole repo. It uses the Symfony process component to run the git client.

Martin Auswöger 4 Dec 14, 2022
Remote or monitor your PocketMine:MP server via browser.

PMRemote Remote or monitor your server via browser. Features Monitor (TPS, Server load, Players count) TODO: Remote (Access server console like RCON,

null 11 Dec 7, 2022
A cross-language remote procedure call(RPC) framework for rapid development of high performance distributed services.

Motan Overview Motan is a cross-language remote procedure call(RPC) framework for rapid development of high performance distributed services. Related

Weibo R&D Open Source Projects 5.8k Dec 20, 2022
Applies a patch from a local or remote file to any package that is part of a given composer project.

Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level in package config or separate JSON file. Declaration-free mode (using embedded info within patch files) is available as well.

Vaimo 245 Dec 15, 2022
Fsociety RAT, The Open Source C++ Remote Administration Tool (RAT)

Fsociety-RAT It was really fun to make this project! This project have a lot of great features and a very good website control for the bots. The final

Elliot Alderson 11 Nov 30, 2022
Creates a WorldBorder for PocketMine-MP servers!

This plugin is not yet ready for Poggit or download It is going through mass changes over the next few days Message my Discord to recieve an older eli

Soulz 9 Sep 5, 2021
Block ads for other servers.

[] NoAdvertisings| v0.0.1 Block ads for other servers. Features Block server ads. Easy to setup. Block server address ads when chatting, using command

Nguyễn Hiếu 4 Aug 28, 2022
A small library to help run PHP servers easily and quickly.

PHP Server A small library to help run PHP servers easily and quickly. Installation composer require ahmard/php-server Usage PHP Built-In Server An i

Ahmad Mustapha 9 Dec 31, 2022
Custom NPC for pocket-mine servers

[Description] Click on above picture to see tutorial video of the plugin. This is an NPC plugin with super easy customization for pocket-mine. Note: W

null 10 Oct 9, 2022