Running your application
Commands
How to run a one-off console command in an environment.
On this page
You can run one console command in an environment and see what it prints:
brewless command production "migrate:status"
Give the command as you would give it to your framework's console, on one line. For a Laravel application that is everything after php artisan.
The command runs in your own container, on the release that is live, and has 50 seconds. When it takes longer, Brewless stops waiting and says so; the command may still be running in its container. Work that takes longer belongs in a queued job.
Brewless sends the command to your application with the environment's ops secret and does not follow a redirect: when your application answers with one, the command is not started.
Warning
On production the client asks for confirmation first.
--forceskips the question.
The Commands tab of the environment in the console does the same.
A line of PHP
To look at something no command shows, run a line of PHP with tinker (not for Laravel for Rust, which has no tinker):
brewless tinker staging "App\\Models\\User::count()"
brewless tinker production "App\\Models\\Order::where('paid', false)->latest()->first()?->id"
It is tinker --execute underneath, and runs where every command runs: your own container, the live release, next to your database. It prints what tinker prints, the value of the last expression or the exception, and ends with tinker's exit code: 1 when the code threw. The client quotes the code for you, so quotes, $ and backslashes arrive as you typed them; in the shell, put the code between double quotes and escape a backslash, or between single quotes as it is.
The same 50 seconds apply. The same goes for production: the client shows the code and asks first.
Warning
Tinker runs any PHP with your application's rights, against real data. Read before you change, and keep changes to data in a command or a migration that is reviewed with your code.
This needs brewless/laravel 1.11.1 or later in the application, and laravel/tinker in its require (a new Laravel application has it there). An older brewless/laravel refuses tinker. Without the CLI, the same line is brewless command <environment> 'tinker --execute="…"'. An interactive tinker is refused: a shell that waits for typing never ends by itself.
What is refused
- Commands that never end by themselves:
queue:work,serve,schedule:work, an interactivetinker, and the like. - Commands that throw data away:
db:wipe,migrate:fresh,migrate:refresh,migrate:resetandmigrate:rollback. Run those at a console of your own, on purpose.
Your application says why it refused, and Brewless shows that.
What Brewless keeps
The audit trail records who ran a command and the name of that command, such as migrate:status or tinker. Brewless keeps neither its arguments, the code you gave tinker, nor what it prints.