Docs / PHP

Deploy PHP

Laravel, Symfony or plain PHP files on PHP 8.3.

Detected by

composer.json or .php files at the top of the project. The general rules are in Deploying.

Build

  • PHP 8.3 with Composer 2.
  • composer install --no-dev --optimize-autoloader when there is a composer.json.
  • The pdo_pgsql extension is there for PostgreSQL.

Start

systemi.toml start, else a Procfile web: line, else PHP's web server on $PORT serving the top folder, so index.php and other .php files answer at their own paths.

Example

index.php

<?php
$u = parse_url(getenv('DATABASE_URL'));
$pdo = new PDO(
    sprintf('pgsql:host=%s;port=%d;dbname=%s;sslmode=require', $u['host'], $u['port'], ltrim($u['path'], '/')),
    $u['user'], $u['pass']
);
$rows = $pdo->query('SELECT id, total FROM orders ORDER BY id DESC LIMIT 20')->fetchAll(PDO::FETCH_ASSOC);
header('Content-Type: application/json');
echo json_encode($rows);

Frameworks

FrameworkStart command or setting
Laravelphp -S 0.0.0.0:$PORT -t public public/index.php
Symfonyphp -S 0.0.0.0:$PORT -t public public/index.php
Plain PHPnothing to set

Good to know

  • Laravel: set APP_KEY, APP_ENV=production, DB_CONNECTION=pgsql and the DB_* values as environment variables, and LOG_CHANNEL=stderr so logs show on the app page. Sessions and cache: use the database or cookie drivers, since storage/ is read-only at run time.
  • Build your front-end assets (npm run build) before you zip; the PHP build doesn't run npm.