- How do I install PsySH for Laravel projects?
- Use Composer to install PsySH globally (`composer global require psy/psysh`) or locally in your project (`composer require --dev psy/psysh`). For Laravel, you can also integrate it via Artisan by creating a custom command or using `php artisan psysh` if configured. Ensure PHP 8.2+ is installed for full compatibility.
- Can PsySH replace Laravel Tinker?
- Yes, PsySH is the foundation of Laravel Tinker and offers more features like advanced autocompletion, clipboard support, and custom themes. Replace `php artisan tinker` with `php artisan psysh` for enhanced functionality. PsySH also supports Laravel’s service container natively, making it a drop-in upgrade.
- What Laravel versions does PsySH support?
- PsySH works with Laravel 8.x, 9.x, and 10.x, as it aligns with PHP 8.2+ support. For older Laravel versions (e.g., 7.x), use PsySH v0.11.x, but note that newer features like experimental readline may not work. Always check the [PsySH manual](https://github.com/bobthecow/psysh/wiki) for version-specific guidance.
- How do I securely use PsySH in CI/CD pipelines?
- Enable Restricted Mode by setting `'trustProject' => 'never'` in your `.psysh.php` config to block untrusted code execution. Use CLI flags like `--no-pager` for scripting and avoid interactive features. For debugging, manually override trust settings only in trusted environments. Always test security configurations in staging first.
- Does PsySH slow down Laravel’s boot time?
- PsySH adds minimal overhead during normal Laravel operations, but its syntax-aware autocompletion and runtime reflection can impact boot time if overused. For production, avoid running PsySH during requests. Benchmark in staging by comparing boot times with and without PsySH loaded via `composer.json` scripts or custom Artisan commands.
- How can I customize PsySH for Laravel-specific debugging?
- Create a `.psysh.php` config file in your project root to customize PsySH. For Laravel, add bindings like `'bindings' => ['app' => fn() => app()]` to access the container directly. Extend PsySH with custom commands using its [command system](https://github.com/bobthecow/psysh/wiki/Commands) to inspect Eloquent models, routes, or queues (e.g., `route:list`).
- What are the alternatives to PsySH for Laravel debugging?
- Laravel Tinker (built-in) is the simplest alternative, but PsySH offers superior features like clipboard integration, better autocompletion, and themes. For lightweight debugging, PHP’s native `php -a` works but lacks Laravel-specific tools. For advanced use cases, PsySH’s modularity and integrations make it the best choice.
- How do I enable clipboard support in PsySH for Laravel?
- Configure clipboard support in `.psysh.php` by setting `'clipboardCommand' => 'pbcopy'` (macOS), `'clipboardCommand' => 'xclip -selection clipboard'` (Linux), or `'clipboardCommand' => 'clip'` (Windows). Ensure the command-line tool is installed. This allows copying/pasting variables or output directly from PsySH, improving workflow efficiency.
- Can PsySH be used for production debugging?
- PsySH is primarily a development tool and should not run in production. However, you can use it in staging or production-like environments for debugging by enabling Restricted Mode (`'trustProject' => 'never'`) and running it via CLI scripts. Avoid interactive sessions in production to prevent security risks or performance impacts.
- How do I troubleshoot PsySH issues in Laravel?
- Start by checking PHP extensions (`ext-readline` or `ext-libedit` for traditional readline). If issues persist, disable experimental features in `.psysh.php` (e.g., `'useExperimentalReadline' => false`). For Laravel-specific problems, verify service container bindings and clear cached configs (`php artisan config:clear`). Refer to the [Troubleshooting guide](https://github.com/bobthecow/psysh/wiki/Troubleshooting) for common fixes.