Free Laravel application deployment with Fly.io

Free Laravel application deployment with Fly.io

The secret to effortless and uninterrupted smooth application development experience for Laravel developers

ยท

4 min read

In the modern digital environment, success in remote settings depends on the efficient and effective deployment of programs or services. This article gives a thorough, step-by-step walkthrough of the procedure to deploy your Laravel application on Fly.io for free.

Fly.io is an alternative since the recent upgrade for the retirement of the free tier on Herokuapp.

Here's an article on Hosting Laravel Apps on Heroku with database if you intend to explore Heroku.

Laravel

Laravel is the most widely used and popular PHP framework for building custom, robust, and scalable web applications.

The Laravel 10 was released on the 14th of February 2023 by the awesome Laravel team led by Taylor Otwell with minimum support for PHP 8.1.

Laravel v10 is the second TS(Long-Term Support) to be introduced following the 12 months release cycle and will be stable for 12 months until another release most likely in February or (Q1) 2024......... Everything about Laravel 10: Deep Dive into the latest features of Laravel 10

Fly

Fly is a platform for hosting databases and full-stack applications close to your users. Since 2017, the Fly.io community has been working tirelessly on this, it's turning out pretty great.

The Fly documentation is pretty neat and easy to navigate for different deployment options and more information.

Fly Installation

Fly installation is available for all operating systems.

  • For installation on Windows: Open the PowerShell command as an administrator

  • Run the command below on the terminal
powershell -Command "iwr https://fly.io/install.ps1 -useb | iex"

After successful installation close the PowerShell command and reopen it.

  • Run the command below to confirm the successful installation
flyctl

Next:

flyctl launch

If this is your first time run the command below to login or signup

flyctl auth login

After successful auth login or sign-up on the browser you'll see this output.

On the PowerShell terminal, this output will be displayed

Deploying Laravel to Fly.io

The Fly.io has a documentation guide for Laravel deployment

To keep this simple we'll use the Laravel application of this tutorial Tailwindcss 3 setup in Laravel 10 using Vite for deployment on Fly.io

Open the Laravel application in any code editor of your choice and go to the terminal.

  • Next Launch the app with the fly command
fly launch

Fly Launch helps you quickly deploy almost any kind of app using a Docker image. To learn more about the different ways to get your app ready to deploy, refer to Fly Launch.

It'll prompt you to set a name for the application and select a region.

Would you like to deploy now? Yes

After the Docker image for the application is successfully built.

The fly launch adds some files to the code base.

Here is what gets added:

  1. Dockerfile - Used to build a container image that is run in fly

  2. .dockerignore - Used to ensure certain files don't make its way into your repository

  3. fly.toml - Configuration specific to hosting on Fly

  4. .fly (formerly docker) - A directory containing configuration files for running Nginx/PHP in a container

Head over to your fly.io dashboard to view the application deployed

Run the command below on the terminal to launch the application.

fly open

Awesome!!!! Up and running.

Monitor Deployment

Deployment progress can be monitored by running flyctl status in the terminal. It will display information about the app, including the deployment status and any errors encountered.

To view application logs run the command below

 fly logs

Fly.io also has a monitoring dashboard for application logs

To view the number of resources for the application

fly scale show

Environment Variables

The fly.toml file also contains the environment variables for the application

Please do not add secrets to the fly.toml file

To set environment secret variables use the command below

flyctl secrets set DB_CONNECTION=mysql

For more Fly secret commands check here

That's all... you're good to go !!! ๐ŸŒš

Conclusion

With Fly.io Laravel developers can easily speed up the application development process and make it accessible to users. Keep in mind to set up any other services or configurations that your app requires to function properly, such as database, caching, or storage systems, to meet the specifications.

Twitter: Alemsbaja | Youtube: Tech with Alemsbaja to stay updated on more articles

Find this helpful or resourceful?? kindly share and feel free to use the comment section for questions, answers, and contributions.

Did you find this article valuable?

Support Alemoh Rapheal Baja by becoming a sponsor. Any amount is appreciated!

ย