Laravel Telescope is an elegant debugging and monitoring tool for Laravel applications. It provides deep insights into requests, exceptions, queries, jobs, and more. This guide will walk you through installing, configuring, and utilizing Laravel Telescope to improve your application’s observability. You can install it with your VPS.
Before setting up Telescope, ensure you have the following:
To install Laravel Telescope, run the following command via Composer:
composer require laravel/telescope
Once the installation is complete, publish the Telescope service provider and assets using:
php artisan telescope:install
Finally, migrate the necessary database tables:
php artisan migrate
After installation, Telescope provides a configuration file located at config/telescope.php
. You can customize the settings as needed.
By default, Telescope is only accessible in the local
environment. If you want to allow access in other environments, modify the gate
method in App\Providers\TelescopeServiceProvider
:
use Laravel\Telescope\Telescope;
use Laravel\Telescope\TelescopeApplicationServiceProvider;
class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
{
protected function gate()
{
Gate::define('viewTelescope', function ($user) {
return in_array($user->email, [
'admin@example.com',
]);
});
}
}
By default, Telescope keeps logs for 24 hours. You can adjust this in the config/telescope.php
file:
'retain_hours' => 48,
Telescope’s dashboard is accessible via /telescope
. If you want to customize this path, update your config/telescope.php
file:
'path' => 'monitoring',
Now, Telescope will be available at /monitoring
instead of /telescope
.
Once configured, start your Laravel application and visit yourdomain.com/telescope
(or your customized path). You will see:
While Telescope is useful in development, it is not recommended for production due to performance overhead. However, if you need to deploy it in production, you can use the TELESCOPE_ENABLED
environment variable:
TELESCOPE_ENABLED=true
Additionally, schedule a command to clear logs periodically to prevent excessive database growth:
php artisan telescope:prune --hours=24
You can automate this by adding a scheduled task in app/Console/Kernel.php
:
$schedule->command('telescope:prune --hours=24')->daily();
Laravel Telescope is a powerful tool that enhances debugging and monitoring in Laravel applications. By installing and configuring it properly, you gain valuable insights into your application’s performance, queries, exceptions, and background jobs.