A repository is built as a PHP project if it contains a composer.json with a recognized framework, an artisan file, or an index.php at the root or in public, web, webroot, html or www.
The image
| Item | Value |
|---|---|
| Image | php:<version>-cli-alpine |
| Version | the one requested by require.php in composer.json, 8.3 by default |
| Server | PHP built-in server (php -S, php artisan serve) |
| Composer | version 2 |
| Variable set | APP_ENV=production |
There is no Apache and no PHP-FPM. The built-in server handles one request at a time per process: for a very busy site, increase the number of instances (Availability and scaling) or use a Dockerfile with Nginx and PHP-FPM.
Extensions
Always installed: opcache, pdo_mysql, pdo_pgsql, zip, bcmath, intl. In addition:
- each
ext-*declared inrequireorrequire-devofcomposer.json("ext-gd": "*","ext-redis": "*"); gdandexiffor Laravel;mysqli,gd,exifandimagickfor WordPress.
Extensions already present in PHP (mbstring, json, curl, openssl, pdo, sqlite3, xml...) do not need to be declared.
Installing dependencies
composer install --no-dev --prefer-dist --no-interaction --no-scripts --no-autoloader
# copy of the code
composer dump-autoload --optimize --no-dev
composer.lock is used if it is committed, and it is recommended: without it, Composer resolves versions on every build. Composer scripts (post-install-cmd, post-autoload-dump) are not run. require-dev dependencies are not installed.
For a private Composer repository, create the COMPOSER_AUTH variable in the Variables panel. It is passed to dependency installation.
{"github-oauth": {"github.com": "ghp_your_token"}}
Frameworks and commands
| Framework | Start command |
|---|---|
| Laravel, Statamic | php artisan serve --host=0.0.0.0 --port=$PORT |
| Symfony, Slim, Lumen, Laminas | php -S 0.0.0.0:$PORT -t public |
| CodeIgniter 4 | php spark serve --host 0.0.0.0 --port $PORT |
| CakePHP | bin/cake server -H 0.0.0.0 -p $PORT |
| Yii 2 | php -S 0.0.0.0:$PORT -t web |
| Craft CMS, Drupal, Kirby | php -S 0.0.0.0:$PORT -t <web root> |
| WordPress, Grav | php -S 0.0.0.0:$PORT -t . |
| PHP without a framework | php -S 0.0.0.0:$PORT -t <web root> |
The web root is the first folder among public, web, webroot, html and www that contains an index.php, otherwise the repository root.
Laravel
Variables to plan for:
APP_ENV=production
APP_KEY=base64:generated-value
APP_DEBUG=false
APP_URL=https://www.example.com
LOG_CHANNEL=stderr
DB_CONNECTION=mysql
DB_HOST=database-internal-address
DB_PORT=3306
DB_DATABASE=app
DB_USERNAME=app
DB_PASSWORD=password
CACHE_STORE=redis
SESSION_DRIVER=redis
REDIS_URL=redis://redis-internal-address:6379
A database's internal address is read in the Database panel of the database service (Databases).
- Generate
APP_KEYonly once, locally, withphp artisan key:generate --show, then copy the value into the variables. A new key invalidates existing sessions and encrypted data. LOG_CHANNEL=stderrsends Laravel logs to the Logs tab. With the default channel, they are written tostorage/logs, which is wiped on every restart.- Files uploaded by your users (
storage/app) must go on a persistent volume or S3-compatible storage. - Behind Webgune, Laravel must trust the proxy to generate HTTPS addresses. In Laravel 11,
bootstrap/app.php:$middleware->trustProxies(at: '*');.
Since Composer scripts do not run at build time, run the preparation commands at startup, with a custom start command:
php artisan migrate --force && php artisan config:cache && php artisan route:cache && php artisan serve --host=0.0.0.0 --port=$PORT
Read Database migrations before running migrations at startup.
Vite assets
A Laravel project often has a vite.config.js. The build recognizes it as Laravel, not as a Vite site, but it does not run npm run build: Node.js is not in the PHP image. Two solutions: commit the public/build folder, or use a multi-stage Dockerfile, one stage with Node.js for the assets and one with PHP.
WordPress
A repository that contains wp-config.php, wp-load.php or wp-content/ is recognized as WordPress. Extensions and uploads written to disk disappear on restart: you need a persistent volume on wp-content/uploads.
The simplest remains the official wordpress image or the matching template (Public Docker images, Template catalog).
Replacing the command
A Procfile at the root replaces the generated command:
web: php -S 0.0.0.0:$PORT -t public public/router.php
Common errors
| Symptom | Cause | What to do |
|---|---|---|
could not find driver | Missing PDO extension | Declare "ext-pdo_sqlite": "*" or the extension you want in composer.json |
No application encryption key has been specified | APP_KEY missing | Add the variable |
Links and forms in http:// | Proxy not trusted | trustProxies(at: '*') and APP_URL in https:// |
| Missing styles on Laravel | Vite assets not built | Commit public/build or use a Dockerfile |
| Uploaded files lost after an update | Written to the service's disk | Persistent volume |
| Unexpected PHP version | require.php constraint in composer.json | Adjust the constraint, for example "php": "^8.3" |
Updated on