Laravel tuning
Published
Updated
Laravel on fortrabbit runs with the defaults of the software template. This page covers what to set beyond them: migrations by hand, logging, sessions, maintenance mode, Envoy and mail. Queues and the scheduler have their own page.
Before tuning
Start with the setup and the deployment. For queues and the scheduler, see queues and scheduler.
Emoji support
Laravel uses the utf8mb4 character set by default, so storing "emojis 🔥" needs no extra configuration. MySQL on fortrabbit indexes utf8mb4 columns at their full length.
Older guides recommend Schema::defaultStringLength(191) in AppServiceProvider. That worked around the 767-byte index prefix of MySQL 5.6 and is not needed here.
Manually running artisan migrate
The template runs migrations as a post deploy command with every deployment. To run them by hand, use SSH:
# login and execute
$ ssh {{app-env-id}}@ssh.{{region}}.frbit.app
$ php artisan migrate --force
With APP_ENV=production, Laravel asks for confirmation before migrating; --force skips the question.
Logging
Laravel writes logs to storage/logs by default. The software template sets LOG_CHANNEL=stack and LOG_STACK=stderr, so the logs show up in the dashboard. Apps set up without the template need these two ENV vars too.
See Laravel logging help for more.
User sessions
Set the session driver with the SESSION_DRIVER ENV var. The storage of an environment is persistent, so the file driver works. For the database driver:
# Create a migration for the session table - locally
$ php artisan session:table
# Apply the migration - locally
$ php artisan migrate
# Add, commit and push the migration file
$ git add .
$ git commit -m "session migration"
$ git push
# Run the migration on the App via SSH remote execution
$ ssh {{app-env-id}}@ssh.{{region}}.frbit.app php artisan migrate --force
Using artisan down
php artisan down puts the app into maintenance mode, and php artisan up ends it. Run them over SSH, or as post deploy commands.
Using Laravel Envoy
Envoy runs tasks on the environment over SSH. An example Envoy.blade.php:
@servers(['fr' => '{{app-env-id}}@ssh.{{region}}.frbit.app'])
@task('ls', ['on' => 'fr'])
ls -lha
@endtask
@task('migrate', ['on' => 'fr'])
php artisan migrate
@endtask
Run locally:
envoy run ls
envoy run migrate
Sending mail
fortrabbit has no sendmail. Send through SMTP or the API of a transactional mail provider. Set MAIL_MAILER, the host, port and credentials, and the from address as ENV vars, see the Laravel mail docs.