fly-apps / fly-laravel

Run your Laravel apps on Fly
40 stars 3 forks source link

Fly-Laravel

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.

Disclaimer

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.

Installation

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.

Usage

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.

Prerequisites

Laravel

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:

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.

Deploy

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.

MySQL

Launch

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.

Some notes when launching a MySQL database:

Deploy

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.

Redis

Launch

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.

Some notes when launching a Redis application:

Deploy

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.

Volume

Mount

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.

Further Reading

For more information about fly.io, check out the Fly.io Docs.

For more Laravel-related content, check out the Laravel-Bytes blog.

License

Fly-Laravel is an open-source software licensed under the MIT license.