Skip to content

Commit 129f997

Browse files
Copilotraphaeltm
andcommitted
Add minimal Laravel sample with compose.yaml and compose.local.yaml
Co-authored-by: raphaeltm <[email protected]>
1 parent 6039a9e commit 129f997

27 files changed

+6368
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
environment: playground
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
id-token: write
15+
16+
steps:
17+
- name: Checkout Repo
18+
uses: actions/checkout@v4
19+
20+
- name: Deploy
21+
uses: DefangLabs/[email protected]
22+
with:
23+
config-env-vars: APP_KEY APP_URL
24+
env:
25+
APP_KEY: ${{ secrets.APP_KEY }}
26+
APP_URL: ${{ secrets.APP_URL }}

samples/laravel/README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Laravel
2+
3+
[![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)
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

samples/laravel/app/.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
.env
3+
storage/*.key
4+
.phpunit.result.cache

samples/laravel/app/.env.example

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
APP_NAME=Laravel
2+
APP_ENV=local
3+
APP_KEY=
4+
APP_DEBUG=true
5+
APP_URL=http://localhost
6+
7+
LOG_CHANNEL=stack
8+
LOG_DEPRECATIONS_CHANNEL=null
9+
LOG_LEVEL=debug

samples/laravel/app/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/vendor/
2+
/node_modules/
3+
.env
4+
.env.backup
5+
.phpunit.result.cache

samples/laravel/app/Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
FROM php:8.3-apache
2+
3+
# Install system dependencies and PHP extensions
4+
RUN apt-get update && apt-get install -y \
5+
curl \
6+
git \
7+
libpq-dev \
8+
zip \
9+
unzip \
10+
&& docker-php-ext-install pdo pdo_mysql \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
# Enable Apache modules
14+
RUN a2enmod rewrite
15+
16+
# Set working directory
17+
WORKDIR /var/www/html
18+
19+
# Copy composer from official image
20+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
21+
22+
# Copy application files (including vendor)
23+
COPY . .
24+
25+
# Copy entrypoint script
26+
COPY docker-entrypoint.sh /usr/local/bin/
27+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
28+
29+
# Create necessary directories with proper permissions
30+
RUN mkdir -p storage/framework/{sessions,views,cache} storage/logs bootstrap/cache && \
31+
chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache && \
32+
chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache
33+
34+
# Configure Apache
35+
RUN echo '<VirtualHost *:8000>' > /etc/apache2/sites-available/000-default.conf && \
36+
echo ' ServerAdmin webmaster@localhost' >> /etc/apache2/sites-available/000-default.conf && \
37+
echo ' DocumentRoot /var/www/html/public' >> /etc/apache2/sites-available/000-default.conf && \
38+
echo '' >> /etc/apache2/sites-available/000-default.conf && \
39+
echo ' <Directory /var/www/html/public>' >> /etc/apache2/sites-available/000-default.conf && \
40+
echo ' AllowOverride All' >> /etc/apache2/sites-available/000-default.conf && \
41+
echo ' Require all granted' >> /etc/apache2/sites-available/000-default.conf && \
42+
echo ' </Directory>' >> /etc/apache2/sites-available/000-default.conf && \
43+
echo '' >> /etc/apache2/sites-available/000-default.conf && \
44+
echo ' ErrorLog ${APACHE_LOG_DIR}/error.log' >> /etc/apache2/sites-available/000-default.conf && \
45+
echo ' CustomLog ${APACHE_LOG_DIR}/access.log combined' >> /etc/apache2/sites-available/000-default.conf && \
46+
echo '</VirtualHost>' >> /etc/apache2/sites-available/000-default.conf
47+
48+
# Update Apache to listen on port 8000
49+
RUN sed -i 's/Listen 80/Listen 8000/g' /etc/apache2/ports.conf
50+
51+
EXPOSE 8000
52+
53+
ENTRYPOINT ["docker-entrypoint.sh"]
54+
CMD ["apache2-foreground"]

samples/laravel/app/artisan

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
define('LARAVEL_START', microtime(true));
5+
6+
/*
7+
|--------------------------------------------------------------------------
8+
| Register The Auto Loader
9+
|--------------------------------------------------------------------------
10+
*/
11+
12+
require __DIR__.'/vendor/autoload.php';
13+
14+
$app = require_once __DIR__.'/bootstrap/app.php';
15+
16+
/*
17+
|--------------------------------------------------------------------------
18+
| Run The Artisan Application
19+
|--------------------------------------------------------------------------
20+
*/
21+
22+
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
23+
24+
$status = $kernel->handle(
25+
$input = new Symfony\Component\Console\Input\ArgvInput,
26+
new Symfony\Component\Console\Output\ConsoleOutput
27+
);
28+
29+
$kernel->terminate($input, $status);
30+
31+
exit($status);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
use Illuminate\Foundation\Application;
4+
use Illuminate\Foundation\Configuration\Exceptions;
5+
use Illuminate\Foundation\Configuration\Middleware;
6+
7+
return Application::configure(basePath: dirname(__DIR__))
8+
->withRouting(
9+
web: __DIR__.'/../routes/web.php',
10+
commands: __DIR__.'/../routes/console.php',
11+
health: '/up',
12+
)
13+
->withMiddleware(function (Middleware $middleware) {
14+
//
15+
})
16+
->withExceptions(function (Exceptions $exceptions) {
17+
//
18+
})->create();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php return array (
2+
'nesbot/carbon' =>
3+
array (
4+
'providers' =>
5+
array (
6+
0 => 'Carbon\\Laravel\\ServiceProvider',
7+
),
8+
),
9+
'nunomaduro/termwind' =>
10+
array (
11+
'providers' =>
12+
array (
13+
0 => 'Termwind\\Laravel\\TermwindServiceProvider',
14+
),
15+
),
16+
);

0 commit comments

Comments
 (0)