# Write a Dockerfile for a CodeIgniter 4 App

Yes. An agent writes a Dockerfile for your CodeIgniter 4 app with the intl extension, public/ as document root and a writable folder, runs it, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-dockerfile/codeigniter/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads what the framework needs from a server before writing an image. In a CodeIgniter app made from codeigniter4/appstarter, `composer.json` requires `php` ^8.2 and `codeigniter4/framework` ^4.7 with `phpunit/phpunit` ^10.5.16 for development, and `README.md` lists the `intl` and `mbstring` extensions as requirements and says the web server must point at `public/`, never the project root. `public/index.php` refuses to run below PHP 8.2, loads `app/Config/Paths.php`, and boots the framework from `vendor/codeigniter4/framework/system`; `public/.htaccess` turns on `mod_rewrite` and sends every request that is not a real file to `index.php`, and carries the `Authorization` header through. `.github/workflows/phpunit.yml` installs `intl, json, mbstring, mysqlnd, xdebug, xml, sqlite3` for its PHP 8.2 and 8.5 matrix, which is the agent's list of what the tests expect.

Then it reads what has to be writable and what must not ship. `app/Config/Paths.php` points `writableDirectory` at `writable/`, whose `cache`, `logs`, `session`, `uploads` and `debugbar` folders are ignored by `.gitignore` except for their `index.html`, and whose `.htaccess` denies web access. `env` is the template for `.env`, which `.gitignore` excludes, and it shows the knobs the image sets: `CI_ENVIRONMENT = production`, `app.baseURL`, and `database.default.*`. `app/Config/Boot/production.php` turns `display_errors` off, and `app/Config/App.php` defaults `baseURL` to `http://localhost:8080/`. There is no Dockerfile, `.dockerignore` or compose file in the starter.

The Dockerfile is a single stage on the official `php` image's Apache variant. It installs `libicu-dev` and builds `intl` with `docker-php-ext-install`, since `mbstring` is already compiled into the image, enables `mod_rewrite`, and rewrites Apache's `DocumentRoot` and the matching `<Directory>` block to `/var/www/html/public` so `public/.htaccess` is honoured and nothing above `public/` is served. Composer comes from the `composer` image with `COPY --from`, and `composer install --no-dev --optimize-autoloader` runs after `composer.json` is copied and before the rest of the source, so a code change does not reinstall the framework. `ENV CI_ENVIRONMENT=production` sets the environment without a `.env` file, `app_baseURL` is left for `docker run -e` because it depends on where the container is reached, and `writable/` is `chown`ed to `www-data`. A `.dockerignore` keeps `vendor/`, `writable/*`, `.env`, `tests/` and `.git` out of the build context.

The sandbox has no Docker, so the agent installs it (`sudo apt-get install -y docker.io`, then starts `dockerd`), builds the image, runs it with a port published and `app_baseURL` set, and requests `/` to see the welcome view from `app/Controllers/Home.php` and a missing path to see the 404 from `app/Views/errors/html/error_404.php` rather than an Apache listing. It also runs `composer install` and `vendor/bin/phpunit` in the sandbox, as the workflow does, because `tests/unit/HealthTest.php` checks `baseURL` and the paths the image depends on, and it adds a job to `phpunit.yml` that builds the image on `ubuntu-24.04`, which the workflow already uses and which has Docker.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Write a Dockerfile for this CodeIgniter 4 application. Read composer.json, README.md, public/index.php, public/.htaccess, app/Config/Paths.php, app/Config/App.php, app/Config/Boot/production.php, env, .gitignore, phpunit.dist.xml and .github/workflows/phpunit.yml first. Use the official php image's Apache variant at a version composer.json allows, install the intl extension with docker-php-ext-install and its libicu-dev dependency, enable mod_rewrite, set Apache's DocumentRoot and its Directory block to /var/www/html/public, copy Composer from the composer image and run composer install --no-dev --optimize-autoloader before copying the application source, set CI_ENVIRONMENT=production in the image, leave app_baseURL to be passed at run time, and make writable/ owned by www-data. Add a .dockerignore for vendor, writable contents, .env, tests and .git. Docker is not installed here: install docker.io, start dockerd, build the image, run it with a port published and app_baseURL set, and request / and an unknown path to confirm the welcome page and the framework's 404. Run composer install and vendor/bin/phpunit in the sandbox, add a CI job that builds the image, and open a pull request that says what to pass at run time.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request that adds `Dockerfile` and `.dockerignore` and a job to `.github/workflows/phpunit.yml`. The description names the base image tag and why, lists the two run-time settings a deployment passes, `app_baseURL` and any `database.default.*` values, and says that `CI_ENVIRONMENT` is baked in as `production`, so the detailed error pages never show from the image.

The run's record keeps the `docker build` output, the two HTTP responses from the running container and the `phpunit` output, so a reviewer can see the welcome page and the framework 404 came from Apache serving `public/` rather than take the Dockerfile's word for it.

Before merging, a reviewer decides whether to pin the image to a patch version, whether to add `mysqli` or `pdo_mysql` now that a database is in reach (the starter's `Database.php` defaults to `MySQLi` with an empty database name, so nothing connects yet), and whether sessions should move off the `writable/session` folder before running more than one replica. The agent names each in the description and changes none.

## Run it on every CodeIgniter app with no image

A team with several PHP apps to containerise runs this once per repository from its own server: one `POST /o/{org}/sessions` per repository, each with that repository in `resources` and a `request_id` that is a UUID v5 of the repository's full name, so a retried call returns the run already started instead of opening a second pull request. Each run installs Docker in its own sandbox and the pull requests arrive independently.

To keep the image building, an automation on the Project with a `github` trigger on `pull_request.opened` and `pull_request.synchronize` and the prompt "if this pull request changes composer.json, composer.lock or the Dockerfile, build the image and comment with the result" reads each new pull request. The trigger puts the pull request after the prompt; only work by an owner, member or collaborator fires it, never a fork's.

## Why run it on Rush?

A PHP image fails in ways a build does not show: the document root one level too high serves `app/` and `.env` to the world, a missing `intl` extension throws on the first `view()` call, and a read-only `writable/` folder fails on the first log line. The agent runs the container in its own sandbox and requests pages from it, so the pull request shows a served welcome page and a framework 404, not a successful build.

Every command stays with the run, from the Docker install to the `phpunit` output, and the pull request can cite them. Doing the same for a dozen PHP apps at once costs no more attention than one, because each run has its own machine and its own record.

## Frequently asked questions

### Why change Apache's DocumentRoot instead of copying the app into public?

`public/index.php` loads `../app/Config/Paths.php` and the framework from `vendor/` by relative paths, so the whole project has to be present with `public/` as the served folder. Pointing `DocumentRoot` at `/var/www/html/public` serves only that folder, which is what `README.md` asks of any web server, and `public/.htaccess` keeps its rewrite rules.

### Which extensions does the image install?

`intl`, built from source with `libicu-dev`. `mbstring`, `json` and `xml` are already compiled into the official image. `mysqli`, `pdo_mysql` and `sqlite3` are not added by default because the starter's `Database.php` names no database; the pull request shows the one-line `docker-php-ext-install` addition for whichever driver the app ends up using.

### How is baseURL set in a container?

Through the environment: CodeIgniter reads `app.baseURL` or `app_baseURL` from the process environment as well as from `.env`, and `env` lists both spellings. The image sets none, because the value depends on the host the container is reached at; `docker run -e app_baseURL=https://example.com/` sets it for that container.

### Does the agent need Docker in the sandbox?

It is not there by default, so the run installs the `docker.io` package and starts `dockerd` before building, and that install is part of the run's record. The CI job it adds runs on `ubuntu-24.04`, the same runner `phpunit.yml` already uses, where Docker is present.

## More CodeIgniter jobs

- [Add File Uploads to a CodeIgniter 4 App](https://getrush.ai/run/add-file-uploads/codeigniter/)
- [Set Up GitHub Actions CI for a CodeIgniter 4 App](https://getrush.ai/run/add-github-actions-ci/codeigniter/)
- [Add a Health Check Endpoint to a CodeIgniter 4 App](https://getrush.ai/run/add-health-checks/codeigniter/)

## The same job on other stacks

- [Write a Dockerfile for a discord.js Bot](https://getrush.ai/run/add-dockerfile/discord-js/)
- [Add a Dockerfile to a .NET Web App](https://getrush.ai/run/add-dockerfile/dotnet/)
- [Add a Dockerfile to a Gradle Spring Boot App](https://getrush.ai/run/add-dockerfile/gradle/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
