PHP
Served from your project root with index.php as the front controller; composer.json is optional.
PHP apps are served from your project root with index.php as the front controller. Requests for
real files (assets, other .php scripts) are served directly; everything else is handled by your
index.php.
- Put an
index.phpat the project root. - If a
composer.jsonis present, its dependencies are installed for you (production, optimized). Nocomposer.jsonis fine for a plain PHP app — omit it.
Supported versions are 8.2, 8.3 and 8.4, defaulting to 8.3 — see Choosing a version.
What gets built
FROM php:<version>-apache
WORKDIR /var/www/html
COPY . /var/www/html
RUN if [ -f composer.json ]; then \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
composer install --no-dev --no-interaction --optimize-autoloader; \
fi
EXPOSE 80Apache serves the project root on port 80. Your whole project is the document root, so anything you ship is reachable — keep configuration and secrets out of the tree and in environment variables instead.
--no-dev means dev dependencies are not installed. If your app needs something at run time, it
belongs in require, not require-dev.
Frameworks
Laravel, Symfony and most others expect the document root to be public/, not the project root. Two
ways to make that work:
- Move the front controller. Put an
index.phpat the root that requirespublic/index.php, and make sure your asset paths still resolve. - Bring your own Dockerfile and set the Apache document root properly. For anything beyond a small app, this is the cleaner option — you also get to run migrations and cache warming at build time.
Only the extensions in the official php:<version>-apache image are available; a framework needing
intl, gd, pdo_mysql or similar needs its own Dockerfile with those installed.
Common failures
| Symptom | Cause |
|---|---|
| Blank white page | A fatal PHP error with display off — read the logs |
404 on every route but / | Framework routing expecting public/ as the document root |
| "Class not found" | composer.json missing, or the dependency is in require-dev |
| A function doesn't exist | The extension isn't in the base image |