How to use Laravel Artisan commands on 000webhost

(Tested on Laravel 8.x)

In the previous tutorial, we’ve learned how to use Composer 2 on 000webhost.
The command line is a powerful tool my friends, and you might need to run some php artisan commands for Laravel someday.

As we’ve explained before, SSH is not available on our free plan. So if you’re planning to run php artisan through the command line, you’re…out of luck :frowning:

Have you just wasted my time?

Before you go, running Artisan commands through the command line is not the only option out there.
Albeit quite hidden, there’s actually an Artisan facade that allows you to run commands directly from within your Laravel app.

You decide how you want to use it, but your PHP file should usually look like this:

# Import the Artisan facade
use Illuminate\Support\Facades\Artisan;
# Run the Artisan command
Artisan::call("command:here", [ 'argument_1' => 'value_1', '--option_2' => 'value_2' ]);
# If you need the output
$output = Artisan::output();

Is it really that easy?

Yes, sometimes all you need is read the docs, and you’ll find what you need easily.