Frameworks
PHP and Laravel
Run Laravel or a plain PHP site, with the right document root and storage.
Two ways to run PHP#
| Run command | Use for |
|---|---|
php-fpm | Production sites. Fast. The web server serves your public/ folder (or the project root if there is none) and passes .php files to PHP. |
php artisan serve --host=0.0.0.0 --port=$APP_PORT | Quick tests, small apps. One process; slower under load. |
PHP projects run on PHP 8, with Composer and these extensions already installed: pdo_mysql, mysqli, pdo_pgsql, pgsql, gd, zip, intl, bcmath, exif, opcache, pcntl. Need another one? Add it with an environment variable, separated by spaces:
PHP_EXTENSIONS=imagick gmpIf your build also needs system libraries, use SYSTEM_PACKAGES (see Environment variables).
Plain PHP (no framework): put index.php at the top of the repository, or in public/, and use php-fpm.
Laravel#
| Setting | Value |
|---|---|
| Build command | composer install --no-dev --optimize-autoloader && php artisan config:cache && php artisan route:cache |
| Run command | php-fpm |
Set these environment variables before the first deploy:
APP_KEY=base64:... # generate locally with: php artisan key:generate --show
APP_ENV=production
APP_DEBUG=false
APP_URL=${APP_URL}Your address is known the moment you create the project, so you never have to guess it. ${APP_URL} is replaced with the real address (for example https://my-site.on.dadisiweb.com) every time you deploy, and it follows you if you rename the project. APP_URL is also filled in for you when you leave it out. APP_KEY must be set by you and kept the same forever, or existing sessions and encrypted data stop working.
Behind our HTTPS front door Laravel must trust the forwarded protocol. In bootstrap/app.php add:
->withMiddleware(function (Middleware $middleware) {
$middleware->trustProxies(at: '*');
})Storage and uploads#
Laravel's storage/ folder lives inside the app and is replaced on every deploy. Point your uploads disk at /data:
// config/filesystems.php
'disks' => [
'uploads' => [
'driver' => 'local',
'root' => env('DATA_DIR', '/data') . '/uploads',
'visibility' => 'public',
],
],Then use Storage::disk('uploads'). Files in /data are private and kept between deploys; to show one to visitors, serve it from your own route (for example with Storage::disk('uploads')->response($path)). Logs are best sent to stderr (LOG_CHANNEL=stderr) so they appear in the Logs tab.
Database#
Create a database, then set DB_CONNECTION, DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME and DB_PASSWORD from its connection details. Run php artisan migrate --force in the build command or from the terminal.
Custom domains#
PHP-FPM projects work with custom domains like any other project; see Custom domains.