Are you tired of managing multiple Laravel Sail applications with port numbers? Do you want to run your applications with custom domain names and SSL support? If so, Fleet is the perfect tool for you.

Fleet is a package that allows you to run multiple Laravel Sail applications locally with custom domain names. It uses Traefik, a reverse proxy that runs on a Docker container, to handle all local web traffic incoming to the :80 port.

Installation

You can install Fleet using Composer:

composer require aschmelyun/fleet --dev

Getting Started

To add Fleet support to your Laravel application, navigate to the root directory of your application and run:

php artisan fleet:add

During setup, you’ll be prompted to enter a domain name for your application. Alternatively, you can pass the domain name as an argument:

php artisan fleet:add my-app.localhost

After the setup is complete, you can start up Sail just like you normally would:

./vendor/bin/sail up

Your site will be available at the domain you provided. If you chose a domain that doesn’t end in .localhost, you will need to add an entry to your hosts file to direct traffic to 127.0.0.1.

Local SSL

Fleet supports local SSL on your custom domains through the power of mkcert. After you’ve installed it on your machine, you can use the --ssl option when using the fleet:add command to enable it for your application:

php artisan fleet:add my-app.localhost --ssl

A local certificate will be generated and stored in ~/.config/mkcert/certs. After spinning up your site with Sail, your specified domain will have HTTPS enabled.

Port Conflicts

When spinning up multiple Laravel Sail applications, you may encounter an error about port conflicts between Docker containers. By default, each service has a port mapped to your local machine, and by default, they’re the same across your applications.

To fix this issue, add different forwarded port numbers to each Laravel application using the .env file:

App #1
FORWARD_DB_PORT=3306
FORWARD_REDIS_PORT=6379

App #2
FORWARD_DB_PORT=4306
FORWARD_REDIS_PORT=7379

This way, both applications can be spun up using Fleet and Sail, and their respective services’ ports won’t conflict.

Additional Usage

Whenever you use fleet:add, a Docker network and container are both started to handle the traffic from your local domain name(s). You can start this manually using:

php artisan fleet:start

If you would like to remove Fleet support from an application and return it back to the default Docker setup, you can run:

php artisan fleet:remove

To stop and remove all Fleet containers and networks that are currently running on your system, you can use the command:

php artisan fleet:stop

Conclusion

Fleet is a powerful tool that makes running multiple Laravel Sail applications locally a breeze. With custom domain names and local SSL support, you can focus on what matters most – developing your application. Give Fleet a try today and see how it can simplify your local development workflow.

Released under an MIT license. More information at https://github.com/aschmelyun/fleet

LEAVE A REPLY

Please enter your comment!
Please enter your name here