Fly-Laravel was created by Fly.io and is a quick way to get a Laravel app running on Fly.io. It was built using Laravel Zero.
Fly-Laravel assumes that you have flyctl installed, and that you have it connected to your Fly.io account. If you need help with this, check out https://fly.io/docs/speedrun/.
These commands will help you set up apps on Fly.io. Remember that running these apps can cost money!
You can find more about Fly.io's free allowance and pricing here.
Run composer require fly-apps/fly-laravel
to install the latest version.
By default, commands are invoked using the vendor/bin/fly-laravel
script. To avoid have to type all that for ecery command, you may configure a shell alias:
alias fly-laravel='vendor/bin/fly-laravel'
To make sure this is always available, you may add this to your shell configuration file in your home directory, such as ~/.zshrc
or ~/.bashrc
, and then restart your shell.
With this package, you can spin up Laravel, MySQL and/or Redis apps on Fly.io . There are two commands for every type of app: launch
and deploy
.
Launch
will create a new application on Fly.io in the organization you choose.Deploy
will (re)deploy the app. This will update the app you've already created with launch
.Run fly-laravel launch
to create a new Laravel application. You will be able to pick the name, what organization to deploy in and what extra services you want to set up.
To set up the app, a number of steps will occur to set up a basic Laravel app:
APP_KEY
will be set as a secret on your app. A note on the configured SESSION_DRIVER
in the fly.toml
file:
After set up, your app will be ready to deploy! In your project root, a .fly
folder will be added alongside a Dockerfile
and a fly.toml
file.
When launching databases you will need to deploy again so launch those before deploying the laravel app.
Run fly-laravel deploy
to deploy your Laravel app. This will update the running app (if any) to include your latest changes. Add the --open
flag to open the app in your browser when it has been deployed.
Run fly-laravel launch:mysql
to create a new MySQL application. You will be able to pick the app name, what organization to deploy in, the MySQL username and the volume name. If a Laravel app is detected, you can opt to use the same organization and primary region.
[laravel app name]-db
will be proposed as the app name. Some notes when launching a MySQL database:
fly.toml
configuration of the Laravel app. Redeploying the Laravel app will be necessary to reflect these changes.DB_CONNECTION
env var in fly.toml
will be set to 'mysql'innodb buffer pool size
will be set to 64MB. Consider optimizing this based on your performance requirements. You can find this in .fly/mysql/fly.toml
, in the [processes]
section.Run fly-laravel deploy:mysql
to deploy the MySQL application. After the deployment we'll run a quick check of the machine resources, and show a warning if the memory is smaller than 1GB.
Run fly-laravel launch:redis
to launch a Redis application. You will be able to pick the app name, what organization to deploy in and the volume name. If a Laravel app is detected, you can opt to use the same organization and primary region.
[laravel app name]-db
will be proposed as the app name.Some notes when launching a Redis application:
fly.toml
configuration. Redeploying the Laravel app will be necessary to reflect these changes.CACHE_DRIVER
and SESSION_DRIVER
env vars in fly.toml
will be set to 'redis'Run fly-laravel deploy:redis
to deploy the Redis application. After the deployment we'll run a quick check of the machine resources, and show a warning if the memory is smaller than 1GB.
Run fly-laravel mount:volume
to mount Volume to your Laravel Fly app's storage directory and persist the files saved here! The command will create the necessary number of Volume(s) in the proper regions, matching the number of machines per region in your Fly app. It will then update your fly.toml
file's mount section to use the Volume(s)' name, and, finally create a script necessary to complete set up of the storage folder for mounting.
After set up, your app will be ready to deploy with changes to mount the created Volume(s)! This is why there is a last prompt from the command asking whether to deploy the changes or not. You can confirm--this will deploy your changes, or decline--your application will be ready to mount the Volume(s) when you deploy manually.
For more information about fly.io, check out the Fly.io Docs.
For more Laravel-related content, check out the Laravel-Bytes blog.
Fly-Laravel is an open-source software licensed under the MIT license.