Laravel Artisan commando's via SSH: complete gids

Artisan is de command-line interface van Laravel waarmee je veelvoorkomende taken automatiseert. In deze handleiding leer je alle belangrijke Artisan commando's die je via SSH kunt gebruiken op je hosting.

Wat is Artisan

Artisan is ingebouwd in Laravel en biedt:

  • Migrations en database beheer
  • Cache management
  • Code generatie (make commands)
  • Queue en job beheer
  • Maintenance mode
  • Veel meer via custom commands

SSH verbinding maken

Voordat je Artisan kunt gebruiken, verbind je via SSH.

Verbinden

ssh gebruikersnaam@jouwdomein.nl
# Of met specifieke poort
ssh -p 7777 gebruikersnaam@server.theory7.net

Naar je project navigeren

cd ~/domains/jouwdomein.nl/project

Artisan testen

php artisan --version
# Output: Laravel Framework 11.x.x
php artisan list
# Toont alle beschikbare commando's

Cache commando's

Cache management is essentieel voor performance.

Alle caches legen

# Leeg alle caches tegelijk
php artisan optimize:clear

Dit combineert:

  • config:clear
  • route:clear
  • view:clear
  • cache:clear

Configuratie cache

# Cache configuratie
php artisan config:cache
# Leeg configuratie cache
php artisan config:clear

Let op: Na config:cache wordt .env niet meer direct gelezen. Wijzigingen vereisen opnieuw cachen.

Route cache

# Cache routes
php artisan route:cache
# Leeg route cache
php artisan route:clear

Versnelt route resolution aanzienlijk.

View cache

# Pre-compileer alle Blade views
php artisan view:cache
# Leeg view cache
php artisan view:clear

Applicatie cache

# Leeg applicatie cache
php artisan cache:clear
# Met specifieke store
php artisan cache:clear --store=file

Optimalisatie voor productie

# Alles cachen voor productie
php artisan optimize
# Of uitgebreid
php artisan config:cache
php artisan route:cache
php artisan view:cache

Database commando's

Beheer je database structuur en data.

Migrations

# Voer pending migrations uit
php artisan migrate
# Met force voor productie
php artisan migrate --force
# Rollback laatste batch
php artisan migrate:rollback
# Rollback specifiek aantal
php artisan migrate:rollback --step=3
# Reset alle migrations
php artisan migrate:reset
# Reset en re-run (destructief!)
php artisan migrate:fresh

Database seeding

# Voer alle seeders uit
php artisan db:seed
# Specifieke seeder
php artisan db:seed --class=UserSeeder
# Fresh migrate met seeding
php artisan migrate:fresh --seed

Migration status

# Bekijk migration status
php artisan migrate:status

Schema dump

# Dump schema naar SQL
php artisan schema:dump
# Met pruning van oude migrations
php artisan schema:dump --prune

Make commando's

Genereer code snel met make commands.

Controllers

# Basis controller
php artisan make:controller UserController
# Resource controller (CRUD)
php artisan make:controller PostController --resource
# API controller
php artisan make:controller Api/ProductController --api

Models

# Basis model
php artisan make:model Post
# Met migration
php artisan make:model Post -m
# Met alles (migration, factory, seeder, controller)
php artisan make:model Post --all

Migrations

# Nieuwe migration
php artisan make:migration create_posts_table
# Wijziging aan bestaande tabel
php artisan make:migration add_status_to_posts_table --table=posts

Andere resources

# Request validation
php artisan make:request StorePostRequest
# Middleware
php artisan make:middleware AuthenticateAdmin
# Event en listener
php artisan make:event OrderShipped
php artisan make:listener SendOrderNotification
# Job
php artisan make:job ProcessPodcast
# Mail
php artisan make:mail OrderConfirmation
# Notification
php artisan make:notification InvoicePaid

Queue commando's

Beheer background jobs.

Queue worker

# Start queue worker
php artisan queue:work
# Met specifieke connection
php artisan queue:work database
# Met timeout en memory limit
php artisan queue:work --timeout=60 --memory=128
# Verwerk alleen N jobs
php artisan queue:work --once
php artisan queue:work --max-jobs=100

Queue beheer

# Bekijk failed jobs
php artisan queue:failed
# Retry failed job
php artisan queue:retry {id}
php artisan queue:retry all
# Verwijder failed job
php artisan queue:forget {id}
php artisan queue:flush  # Alle failed jobs
# Restart workers (na code wijziging)
php artisan queue:restart

Maintenance mode

Zet je site tijdelijk offline.

Activeren

# Basis maintenance mode
php artisan down
# Met custom bericht
php artisan down --message="We zijn zo terug!"
# Met retry header (seconden)
php artisan down --retry=60
# Specifieke IPs toestaan
php artisan down --allow=123.456.789.0
# Met secret bypass URL
php artisan down --secret="bypass-token"

Met secret kun je de site bekijken via:

https://jouwdomein.nl/bypass-token

Deactiveren

php artisan up

Debugging commando's

Handige commando's voor debugging.

Routes bekijken

# Lijst alle routes
php artisan route:list
# Filter op naam
php artisan route:list --name=admin
# Filter op methode
php artisan route:list --method=GET

Environment info

# Toon huidige environment
php artisan env
# Encrypt .env waardes
php artisan env:encrypt

Tinker (REPL)

# Start interactieve shell
php artisan tinker
# In tinker:
> User::count()
> User::find(1)
> App::environment()

Schedule commando's

Beheer geplande taken.

Schedule uitvoeren

# Handmatig scheduler uitvoeren
php artisan schedule:run
# Bekijk geplande taken
php artisan schedule:list
# Test specifieke command
php artisan schedule:test

Schedule in cronjob

Voeg toe aan crontab:

* * * * * cd /path/to/project && php artisan schedule:run >> /dev/null 2>&1

Storage commando's

Beheer storage en bestanden.

# Maak public storage link
php artisan storage:link
# Verifieer links
ls -la public/storage

Storage cleanup

Custom command of handmatig:

# Verwijder temp bestanden ouder dan X dagen
find storage/app/temp -mtime +7 -delete

Deployment commando's

Typische deployment workflow:

# 1. Maintenance aan
php artisan down
# 2. Dependencies updaten (indien nodig)
composer install --no-dev --optimize-autoloader
# 3. Migrations
php artisan migrate --force
# 4. Cache opbouwen
php artisan config:cache
php artisan route:cache
php artisan view:cache
# 5. Queue workers herstarten
php artisan queue:restart
# 6. Maintenance uit
php artisan up

One-liner voor deployment

php artisan down && composer install --no-dev --optimize-autoloader && php artisan migrate --force && php artisan optimize && php artisan up

Custom Artisan commando's

Maak je eigen commando's:

php artisan make:command SendWeeklyReport

Dit maakt app/Console/Commands/SendWeeklyReport.php.

Gerelateerde artikelen

Hulp nodig?

We staan voor je klaar! Loop je ergens tegenaan of heb je vragen? Ons supportteam helpt je graag persoonlijk verder. Stuur ons een berichtje via het ticketsysteem - we reageren meestal binnen een paar uur en denken graag met je mee.