|
| 1 | +# Laravel |
| 2 | + |
| 3 | +[](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-laravel-template%26template_owner%3DDefangSamples) |
| 4 | + |
| 5 | +This sample shows how to deploy a minimal [Laravel](https://laravel.com/) application with Defang. Laravel is a popular PHP web application framework with expressive, elegant syntax. |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +1. Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 10 | +2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account |
| 11 | +3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/) |
| 12 | + |
| 13 | +## Development |
| 14 | + |
| 15 | +To run the application locally for development, use the local compose file: |
| 16 | + |
| 17 | +```bash |
| 18 | +docker compose -f compose.local.yaml up --build |
| 19 | +``` |
| 20 | + |
| 21 | +This will: |
| 22 | + |
| 23 | +- Build the Laravel application with development settings |
| 24 | +- Enable debug mode and hot reload via volume mounting |
| 25 | +- Start the application on port 8000 |
| 26 | + |
| 27 | +You can access the application at `http://localhost:8000` once the container is running. |
| 28 | + |
| 29 | +Changes to your Laravel code will be reflected immediately without needing to rebuild the container. |
| 30 | + |
| 31 | +### Available Endpoints |
| 32 | + |
| 33 | +- `/` - Returns a welcome JSON response with Laravel version |
| 34 | +- `/health` - Health check endpoint |
| 35 | +- `/up` - Laravel built-in health check endpoint |
| 36 | + |
| 37 | +## Configuration |
| 38 | + |
| 39 | +For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration): |
| 40 | + |
| 41 | +> Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you. |
| 42 | +
|
| 43 | +### `APP_KEY` |
| 44 | + |
| 45 | +The application key is used for encryption. Laravel requires this to be set. |
| 46 | + |
| 47 | +*You can easily set this to a random string using `defang config set APP_KEY --random`* |
| 48 | + |
| 49 | +Alternatively, generate one using: |
| 50 | +```bash |
| 51 | +php artisan key:generate --show |
| 52 | +``` |
| 53 | + |
| 54 | +### `APP_URL` (Optional) |
| 55 | + |
| 56 | +The URL where your application will be accessed. Defaults to `http://localhost:8000`. |
| 57 | + |
| 58 | +```bash |
| 59 | +defang config set APP_URL=https://your-domain.com |
| 60 | +``` |
| 61 | + |
| 62 | +## Deployment |
| 63 | + |
| 64 | +> [!NOTE] |
| 65 | +> Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 66 | +
|
| 67 | +### Defang Playground |
| 68 | + |
| 69 | +Deploy your application to the Defang Playground by opening up your terminal and typing: |
| 70 | + |
| 71 | +```bash |
| 72 | +defang compose up |
| 73 | +``` |
| 74 | + |
| 75 | +### BYOC |
| 76 | + |
| 77 | +If you want to deploy to your own cloud account, you can [use Defang BYOC](https://docs.defang.io/docs/tutorials/deploy-to-your-cloud). |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +Title: Laravel |
| 82 | + |
| 83 | +Short Description: A minimal Laravel application running on Defang. |
| 84 | + |
| 85 | +Tags: Laravel, PHP, Web Framework |
| 86 | + |
| 87 | +Languages: PHP |
0 commit comments