Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions samples/laravel/.github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Deploy

on:
push:
branches:
- main

jobs:
deploy:
environment: playground
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Deploy
uses: DefangLabs/defang-github-action@v1.2.0
with:
config-env-vars: APP_KEY APP_URL
env:
APP_KEY: ${{ secrets.APP_KEY }}
APP_URL: ${{ secrets.APP_URL }}
87 changes: 87 additions & 0 deletions samples/laravel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Laravel

[![1-click-deploy](https://raw.githubusercontent.com/DefangLabs/defang-assets/main/Logos/Buttons/SVG/deploy-with-defang.svg)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-laravel-template%26template_owner%3DDefangSamples)

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.

## Prerequisites

1. Download [Defang CLI](https://github.com/DefangLabs/defang)
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)

## Development

To run the application locally for development, use the local compose file:

```bash
docker compose -f compose.local.yaml up --build
```

This will:

- Build the Laravel application with development settings
- Enable debug mode and hot reload via volume mounting
- Start the application on port 8000

You can access the application at `http://localhost:8000` once the container is running.

Changes to your Laravel code will be reflected immediately without needing to rebuild the container.

### Available Endpoints

- `/` - Returns a welcome JSON response with Laravel version
- `/health` - Health check endpoint
- `/up` - Laravel built-in health check endpoint

## Configuration

For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration):

> 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.

### `APP_KEY`

The application key is used for encryption. Laravel requires this to be set.

*You can easily set this to a random string using `defang config set APP_KEY --random`*

Alternatively, generate one using:
```bash
php artisan key:generate --show
```

### `APP_URL` (Optional)

The URL where your application will be accessed. Defaults to `http://localhost:8000`.

```bash
defang config set APP_URL=https://your-domain.com
```

## Deployment

> [!NOTE]
> Download [Defang CLI](https://github.com/DefangLabs/defang)

### Defang Playground

Deploy your application to the Defang Playground by opening up your terminal and typing:

```bash
defang compose up
```

### BYOC

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).

---

Title: Laravel

Short Description: A minimal Laravel application running on Defang.

Tags: Laravel, PHP, Web Framework

Languages: PHP
4 changes: 4 additions & 0 deletions samples/laravel/app/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
.env
storage/*.key
.phpunit.result.cache
9 changes: 9 additions & 0 deletions samples/laravel/app/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
15 changes: 15 additions & 0 deletions samples/laravel/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/vendor/
/node_modules/
.env
.env.backup
.phpunit.result.cache
/storage/logs/*
/storage/framework/sessions/*
/storage/framework/views/*
/storage/framework/cache/*
/bootstrap/cache/*
!/storage/logs/.gitkeep
!/storage/framework/sessions/.gitkeep
!/storage/framework/views/.gitkeep
!/storage/framework/cache/.gitkeep
!/bootstrap/cache/.gitkeep
54 changes: 54 additions & 0 deletions samples/laravel/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM php:8.3-apache

# Install system dependencies and PHP extensions
RUN apt-get update && apt-get install -y \
curl \
git \
libpq-dev \
zip \
unzip \
&& docker-php-ext-install pdo pdo_mysql \
&& rm -rf /var/lib/apt/lists/*

# Enable Apache modules
RUN a2enmod rewrite

# Set working directory
WORKDIR /var/www/html

# Copy composer from official image
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Copy application files (including vendor)
COPY . .

# Copy entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

# Create necessary directories with proper permissions
RUN mkdir -p storage/framework/{sessions,views,cache} storage/logs bootstrap/cache && \
chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache && \
chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache

# Configure Apache
RUN echo '<VirtualHost *:8000>' > /etc/apache2/sites-available/000-default.conf && \
echo ' ServerAdmin webmaster@localhost' >> /etc/apache2/sites-available/000-default.conf && \
echo ' DocumentRoot /var/www/html/public' >> /etc/apache2/sites-available/000-default.conf && \
echo '' >> /etc/apache2/sites-available/000-default.conf && \
echo ' <Directory /var/www/html/public>' >> /etc/apache2/sites-available/000-default.conf && \
echo ' AllowOverride All' >> /etc/apache2/sites-available/000-default.conf && \
echo ' Require all granted' >> /etc/apache2/sites-available/000-default.conf && \
echo ' </Directory>' >> /etc/apache2/sites-available/000-default.conf && \
echo '' >> /etc/apache2/sites-available/000-default.conf && \
echo ' ErrorLog ${APACHE_LOG_DIR}/error.log' >> /etc/apache2/sites-available/000-default.conf && \
echo ' CustomLog ${APACHE_LOG_DIR}/access.log combined' >> /etc/apache2/sites-available/000-default.conf && \
echo '</VirtualHost>' >> /etc/apache2/sites-available/000-default.conf

# Update Apache to listen on port 8000
RUN sed -i 's/Listen 80/Listen 8000/g' /etc/apache2/ports.conf

EXPOSE 8000

ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["apache2-foreground"]
31 changes: 31 additions & 0 deletions samples/laravel/app/artisan
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env php
<?php

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
*/

require __DIR__.'/vendor/autoload.php';

$app = require_once __DIR__.'/bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Artisan Application
|--------------------------------------------------------------------------
*/

$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);

$status = $kernel->handle(
$input = new Symfony\Component\Console\Input\ArgvInput,
new Symfony\Component\Console\Output\ConsoleOutput
);

$kernel->terminate($input, $status);

exit($status);
18 changes: 18 additions & 0 deletions samples/laravel/app/bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
Empty file.
39 changes: 39 additions & 0 deletions samples/laravel/app/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "defang/laravel-sample",
"type": "project",
"description": "A minimal Laravel application for Defang",
"keywords": ["laravel", "defang"],
"license": "MIT",
"require": {
"php": "^8.2",
"laravel/framework": "^11.0"
},
"autoload": {
"psr-4": {
"App\\": "app/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"php-http/discovery": true
}
},
"minimum-stability": "stable",
"prefer-stable": true
}
Loading
Loading