Skip to content

szepeviktor/running-laravel

Repository files navigation

Running a Laravel application

theories

list features -> orgranize them into categories, see GH issue!

ErrorDocument 500 /errors/HTTP_INTERNAL_SERVER_ERROR.html ErrorDocument 503 /errors/HTTP_SERVICE_UNAVAILABLE.html https://templates.mailchimp.com/resources/inline-css/

mysqldump --routines --triggers --events

Setting up GitHub repository

Entry points

Startup methods.

  1. Web - through public/index.php
  2. CLI - through artisan
  3. Queue workers - through artisan queue:work
  4. Cron job - through artisan schedule:run

Security

  • HTTP method not in routes
  • HTTP 404
  • CSRF token mismatch (Google Translate, Facebook app, Google Search "Cached")
  • Failed login attempts
  • Requests for .php files
  • Non-empty hidden field in forms

Security Exceptions

protected $securityExceptions = [
        \Illuminate\Session\TokenMismatchException::class,
        \Illuminate\Validation\ValidationException::class,
        \Illuminate\Auth\Access\AuthorizationException::class,
        \Illuminate\Database\Eloquent\ModelNotFoundException::class,
        \Symfony\Component\HttpKernel\Exception\HttpException::class,
        \Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class,
];

Caches

Use Redis PECL extension instead of Predis, and the key hash tag.

  • Compiled classes /bootstrap/cache/compiled.php removed in 5.4
  • Services /bootstrap/cache/services.php - flushed in composer script post-autoload-dump
  • Discovered packages /bootstrap/cache/packages.php - flushed in composer script post-autoload-dump
  • Configuration cache /bootstrap/cache/config.php - flushed by artisan config:clear
  • Routes cache /bootstrap/cache/routes.php - flushed by artisan route:clear
  • Events cache /bootstrap/cache/events.php - flushed by artisan event:clear
  • Application cache (CACHE_DRIVER) - flushed by artisan cache:clear
  • Blade templates cache /storage/framework/views/*.php - flushed by artisan view:clear

See /vendor/laravel/framework/src/Illuminate/Foundation/Application.php

Caching depends on APP_ENV variable.

Static analysis

Throttle 404 errors

routes/web.php

use Illuminate\Support\Facades\Route;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

// Throttle 404 errors
Route::fallback(static function () {
    throw new NotFoundHttpException();
})->middleware('throttle:10,1');

Is Laravel down?

  1. ./artisan tinker --execute='printf("Application is %s.",App::isDownForMaintenance()?"down":"up");'
  2. ls storage/framework/down
  3. ./artisan isdown - using Commands/IsDownForMaintenance.php

Check route methods

./artisan route:check - using Commands/RouteCheckCommand.php

Check PHP version after PHP upgrade

Insert this line in the top of bootstrap/app.php

if (phpversion() !== '8.2.7') dd('Different PHP version:', phpversion());

Check all four entry points!

Debugging

https://github.com/spatie/ray

Add the following to app/Providers/AppServiceProvider.php

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

    public function boot(): void
    {
        DB::listen(static function ($query) {
            Log::info('SQL query', [$query->sql, $query->bindings, $query->time]);
        });
    }

URL categories

  • Root files - stored in public/ and public/.well-known/ directories
  • Static assets - stored in various subdirectories of public/
  • User generated media - stored in storage/app/public/ directory
  • Virtual URL-s are handled by Laravel started in public/index.php
  • Explicit API calls prefixed with /api/ in URL path

Nova

Custom exception handling https://nova.laravel.com/docs/4.0/installation.html#error-reporting