Skip to main content

Laravel (PHP)

Laravel is a popular PHP framework for building robust web applications with expressive, elegant syntax. It provides a powerful routing system, ORM (Eloquent), queueing, caching, background jobs and more.

Check out the official documentation here.

Deploy a Laravel App

Deployment Instructions

We recommend using a Dockerfile as the build system for production deployments on Hostless. This ensures consistent, reproducible builds.

  1. Create or use an existing Laravel repository

  2. Click on 'Create New App' on Hostless

  3. Choose a suitable app name

  4. Choose your Git provider account

  5. Select your Laravel repository

  6. Choose a build system

    1. 'Docker' — Hostless looks for a Dockerfile in the repository root and builds the image according to your instructions
  7. (Optional) Input a start command if you want to override the image CMD

  8. Hostless automatically sets the PORT environment variable your app should listen on

  9. Ensure your Laravel app reads the port from $_ENV['PORT'] (or default to 8080) when configuring your web server (e.g., PHP-FPM + Nginx or Caddy)

  10. Set production environment variables:

  • APP_ENV=production
  • APP_DEBUG=false
  • APP_KEY (required; generate via php artisan key:generate --show and copy the value)
  • Database credentials (e.g., DB_CONNECTION, DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD)
  • Any other necessary secrets (e.g., cache/session drivers, queues, mailer)

Example Dockerfile (Multi-stage)

# Build stage
FROM composer:2 AS vendor
WORKDIR /app
COPY composer.json composer.lock ./
RUN composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader

# App stage
FROM php:8.2-fpm-alpine AS app
WORKDIR /var/www/html

# Install system deps as needed (pdo, gd, etc.)
RUN docker-php-ext-install pdo pdo_mysql

COPY . .
COPY --from=vendor /app/vendor ./vendor

# Cache/config optimize for production
RUN php artisan config:cache && \
php artisan route:cache && \
php artisan view:cache || true

# Web server stage (Caddy example)
FROM caddy:2-alpine AS web
WORKDIR /srv

# Copy app code
COPY --from=app /var/www/html /srv

# Caddyfile expects PORT from env
# Example Caddyfile
# :{$PORT}
# php_fastcgi 127.0.0.1:9000
# file_server

# Run PHP-FPM alongside Caddy (in production you might prefer separate processes or s6/supervisord)
# For simplicity, consider a single-process server like RoadRunner or FrankenPHP if suitable

Note: You can use Nginx instead of Caddy. The key point is to forward requests to PHP-FPM and listen on the $PORT value provided by Hostless.

Environment Variables

  • PORT — set by Hostless at runtime. Ensure your web server listens on this port.
  • APP_ENVproduction
  • APP_DEBUGfalse in production
  • APP_KEY — required; keep secret
  • DB_* — database connection details

Health Checks

Configure a lightweight route like /health that returns 200 OK to use as an HTTP health check path in the app configuration.

Logs & Metrics

  • Application logs are collected from STDOUT/STDERR and visible in the Hostless dashboard
  • Use Laravel Telescope or external APM if you need deeper insights