# Running afaq with Docker (local development)

A three-service stack that runs afaq from a **bind-mounted** copy of this repo —
edit files on the host and they're live in the container, no rebuild.

| Service       | What it is                                  | Host URL / port                       |
| ------------- | ------------------------------------------- | ------------------------------------- |
| `app`         | PHP 7.4 + Apache, DocumentRoot `public_html`| http://localhost:8090 / https://localhost:8453 |
| `sftp`        | Chrooted SFTP + HTTP file server            | SFTP `localhost:2223`, HTTP `localhost:8084` |
| `filebrowser` | Web UI to browse/upload the SFTP files      | http://localhost:8086                 |

Ports are offset so this stack runs alongside `maqsurah_main`'s.

## Prerequisites

- Docker Desktop.
- A MySQL server afaq can reach (see **Database** below). **No database container
  is included** — afaq uses your existing MySQL.

## Quick start

```powershell
docker compose build
docker compose up -d
```

Then open http://localhost:8090.

Stop with `docker compose down` (uploaded files and the filebrowser DB persist in
named volumes; add `-v` to wipe them).

## Database

`localhost` inside the container is the container, not your PC. In `.env`:

- **MySQL on this PC** → `MASTER_HOST="host.docker.internal"` (the app service
  has the `host-gateway` mapping for this).
- **MySQL on the local network** → `MASTER_HOST="192.168.x.x"` (the bridge
  network NATs out to the LAN).

Make sure the MySQL user is allowed to connect from the container's IP and that
the DB is reachable before `up`. See `.env.docker.example` for the full set of
keys.

## SFTP file storage

On every `up`, the **app** entrypoint overwrites these existing `.env` keys' values
in place (and adds `FILE_SYSTEM_DRIVER` if it isn't there yet):

```
FILE_SYSTEM_DRIVER="FTP"
SFTP_HOST="sftp"
SFTP_USER="afaq_ftp_user"
SFTP_PASSWORD="afaq_ftp_pwd"
```

How it fits together:

- The app uploads via SFTP to the `sftp` service (host `sftp`, port 22). Files
  land in the user's `uploads/` dir.
- The app reads files back over `http://sftp/<relative-path>` — that `uploads/`
  dir **is** the sftp Apache DocumentRoot root, so the paths line up.
- **filebrowser** (http://localhost:8086) is the human-facing viewer/uploader,
  opening straight into the same upload root (no login).

To keep afaq on local-disk storage instead, set `FILE_SYSTEM_DRIVER: "LOCAL"` on
the `app` service in `docker-compose.yml` and `up` again.

Credentials live in one place — the `SFTP_USER`/`SFTP_PASS` env on both the
`app` and `sftp` services in `docker-compose.yml`. Change them there and `up`
again.

## Notes

- `vendor/` is committed and used as-is — the entrypoint does **not** run
  composer (it fails on this project; see CLAUDE.md).
- PHP tuning: edit `docker/app/php.ini`, then `docker compose restart app`.
- The app container runs PHP 7.4. To exercise PHP 5.6, use Laragon (see
  `docs/php-version.md`); this stack is fixed to 7.4.
- A shell in the app container: `docker exec -it afaq-app bash`.
