Rock8Cloud
Blueprints

Laravel — Blueprint

Fullstack web app with PHP 8.2, Laravel 11, and PostgreSQL

Fullstack web application built with PHP 8.2+, Laravel 11, and PostgreSQL. Serves a Blade-rendered HTML page and a JSON API. Intended as a starting point for Kubernetes-deployed services: one table, one API endpoint, full Docker support out of the box.

Tech stack:

LayerTechnology
LanguagePHP 8.2+
FrameworkLaravel 11
DatabasePostgreSQL
MigrationsLaravel migrations (Eloquent)
ORMEloquent
Web serverApache (mod_rewrite)

The application runs on port 80. The root / serves an HTML page; the API is available under /api/.


Project Structure

app/
├── Http/Controllers/
│   ├── SpaceTargetController.php    # GET /api/targets
│   └── InfoController.php           # GET /api/info
└── Models/
    └── SpaceTarget.php              # Eloquent model (table: space_target)

routes/
├── api.php                          # /api/targets, /api/info
└── web.php                          # / → Blade home view

resources/views/
└── home.blade.php                   # HTML page with space targets table

config/
└── database.php                     # Custom connection config (DATABASE_URL or DB_*)

database/migrations/
└── 2025_01_01_000000_create_space_targets_table.php  # Creates table + seed data

docker/
└── entrypoint.sh                    # Runs php artisan migrate --force, then starts Apache

Key design decisions:

  • config/database.php parses DATABASE_URL (the postgres:// format from managed services) or falls back to individual DB_* variables. This replaces the default Laravel .env-only approach, which does not understand the postgres:// scheme natively.
  • APP_KEY is required for Laravel to start. In the Docker Compose file a development key is pre-set. For production, generate a real one: php artisan key:generate --show.
  • Migrations run automatically on container startup via docker/entrypoint.sh (php artisan migrate --force). There is no separate migration job.
  • SpaceTarget is the demo entity with $timestamps = false since the table has no created_at/updated_at columns. To add your own domain: create a model in app/Models/, a migration in database/migrations/, and a controller in app/Http/Controllers/. Register routes in routes/api.php.
  • The demo files can be deleted once you no longer need them.

Environment Variables

The application runs on port 80 and requires a PostgreSQL database.

VariableRequiredDescription
APP_KEYyesLaravel app key — generate with php artisan key:generate --show
APP_ENVnoproduction or local (default: production)
APP_DEBUGnotrue / false (default: false)
APP_URLnoFull URL of the app, e.g. https://example.com

Database connection is configured via one of two approaches:

VariableRequiredExample
DATABASE_URLyespostgres://user:pass@host:5432/dbname?sslmode=require

Option B — Individual variables

VariableRequiredDefaultDescription
DB_HOSTno127.0.0.1Database host
DB_PORTno5432Database port
DB_NAMEnolaravelDatabase name
DB_USERnopostgresDatabase user
DB_PASSWORDno(empty)Database password
DB_SSL_MODEnopreferSSL mode, e.g. require or disable

DATABASE_URL takes precedence. If it is set, the individual DB_* variables are ignored.


Running Locally

With Docker Compose

docker compose up

Starts the application together with a PostgreSQL instance. APP_KEY and DATABASE_URL are set automatically. No additional configuration needed.

Standalone

Requires PHP 8.2+, Composer, and a running PostgreSQL instance.

# install dependencies
composer install

# run — Option A
DATABASE_URL=postgres://postgres:postgres@localhost:5432/spacedb \
  APP_KEY=base64:$(openssl rand -base64 32) \
  php artisan migrate
  php artisan serve

# run — Option B
DB_HOST=localhost DB_USER=postgres DB_PASSWORD=secret \
  APP_KEY=base64:$(openssl rand -base64 32) \
  php artisan migrate
  php artisan serve

On this page