> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fly.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Laravel on Fly.io

<img src="https://mintcdn.com/fly-io/izaS1l2UMuz6sm1H/images/laravel-intro.webp?fit=max&auto=format&n=izaS1l2UMuz6sm1H&q=85&s=9a7f1026c50dff6d356d685c0ce18392" alt="" width="720" height="342" data-path="images/laravel-intro.webp" />

Getting an application running on Fly.io is essentially working out how to package it as a deployable image. Once packaged, it can be deployed to the Fly.io platform.

In this guide we’ll learn how to deploy a [Laravel](https://laravel.com/) application on Fly.io.

For an overview of how to configure your application with services like caching, databases, and queues, reading through our [Full Stack Laravel](https://fly.io/laravel-bytes/full-stack-laravel/) post is the best place to start.

## Prepare a Laravel app

Bring your own Laravel app, or create a new one!

If you want to start fresh, here's how to set up a new application. You'll need PHP 8+ and [composer](https://getcomposer.org/) installed locally. You can check your PHP version using `php --version`.

```bash theme={null}
composer create-project laravel/laravel fly-laravel
cd fly-laravel
php artisan serve
```

You should be able to visit `http://localhost:8000` and see the home page.

## Deploy to Fly.io

### Install Fly

First, [install flyctl](/flyctl/install), the Fly.io CLI, and [sign up to Fly.io](/getting-started/sign-up-sign-in#first-time-or-no-fly-account-sign-up-for-fly) if you haven't already.

### Launch

Next, we'll use the `launch` command to automagically configure your app for Fly and deploy it to the Fly cloud. This will add a few files to your code base--but, don't worry, it will ask before overwriting anything.

**If you haven't already, go ahead and run `fly launch`!**

```bash theme={null}
fly launch
```

This would detect that your project is built with Laravel. Afterwhich it would provide a summary of the default configuration that would be given to your app.

```
We're about to launch your Laravel app on Fly.io. Here's what you're getting:

Organization: Personal                                                   (fly launch defaults to the personal org)
Name:         fly-lara-app                                               (derived from your directory name)
Region:       Paris, France                                              (this is the fastest region for you)
App Machines: shared-cpu-1x, 1GB RAM                                     (most apps need about 1GB of RAM)
Postgres:     <none>                                                     (not requested)
Redis:        Pay-as-you-go Plan: 10 GB Max Data Size, eviction disabled (determined from app source)
Tigris:       <none>                                                     (not requested)

? Do you want to tweak these settings before proceeding? (y/N) 
```

Extensions like [Postgres](/mpg/index) ( database ), [Redis](/upstash/redis) ( cache ), and [Tigris](/tigris#main-content-start) ( storage ) can also be added by default based on whether there's an existing, similar connection found for your Laravel project.

<Warning>
  **Please note** that these extension apps will also incur their own **usage costs**! You can select "y" in order to adjust the default settings and remove any extension you don't need.
</Warning>

#### Launch Configuration

Once you accept the configuration, this would proceed with **adding [default secrets](https://github.com/superfly/flyctl/blob/master/scanner/laravel.go#L41-L50)**, **deploying the accepted extensions**, and **generating files** on your project:

1. `.github/workflows/fly-deploy.yml`, `fly.toml` - Configurations specific to hosting on Fly
2. [.fly directory](https://github.com/fly-apps/dockerfile-laravel/tree/main/resources/views/fly) - A directory containing configuration files for running Nginx/PHP in a container
3. [Dockerfile](https://github.com/fly-apps/dockerfile-laravel/blob/main/resources/views/dockerfile.blade.php) -  Used to build a container image that is run in fly
4. [.dockerignore](https://github.com/fly-apps/dockerfile-laravel/blob/main/resources/views/fly/dockerignore.blade.php) - Used to ensure certain files don’t make its way into your image

With the configuration files and extenstion apps in place, an image is built for your app using your project and the Dockerfile generated for it. This image is then finally used to deploy your app.

#### Success!

You should be able to visit `https://your-app-name.fly.dev` and see the Laravel demo home page.

That's it! Run `fly apps open` to see your deployed app in action.

Try a few other commands:

* [`fly logs`](/flyctl/cmd/fly_logs) - Tail your application logs
* [`fly status`](/flyctl/cmd/fly_status) - View your app's current deployment status
* [`fly ssh console`](/flyctl/cmd/fly_ssh_console) - Open a terminal on your VM
* [`fly deploy`](/flyctl/cmd/fly_deploy) - Deploy the application after making changes

## Customizing your app

If you have other environment variables to set, you can edit the `fly.toml` file and add them.

```toml theme={null}
[env]
# Set any env vars you want here
# Caution: Don't add secrets here
APP_URL = "https://fly-hello-laravel.fly.dev"
```

Replace this with the URL your app will be served on (by default, `"https://<your-app-name>.fly.dev"`).

For sensitive data, you can set **secrets** with the [`fly secrets set`](/flyctl/cmd/fly_secrets_set) command:

```bash theme={null}
fly secrets set SOME_SECRET_KEY=<the-value-from-your-env-file>
```

### Deploy

Once you've made changes for your app locally, you can run `fly deploy` to deploy your changes.

### Some Notes

Running `fly launch` (and later `fly deploy`) uses the `Dockerfile` to build a container image, copying your application files into the resulting image.

Fly doesn't care about the state of your git repository - it copies whatever files are present (except for files ignored by `.dockerignore`).
