ARXD deployment
How code gets onto the server, how the database is brought along with it, and how to get back if a step goes wrong.
This is a single production host with no staging environment. Every write is immediately live for real customers. That fact drives every rule below.
Related: docs/deployment.md (the long-form runbook), docs/go-live.md (the launch checklist), ARXD_ENVIRONMENT.md (variables), ARXD_IMPLEMENTATION_STATUS.md (what is actually built).
1. The host
| Item | Value | | --- | --- | | Path | /var/www/vhosts/arxd.org/httpdocs | | PHP | /opt/plesk/php/8.3/bin/php (8.3.36) | | Web server | Plesk-managed Apache with .htaccess overrides | | Database | MariaDB, schema ARXD, 87 tables | | Owner | arxd.org_lzf2t1q5l6r:psacln | | open_basedir | /var/www/vhosts/arxd.org/:/tmp/ | | Cron | tools/worker.php every minute |
The bare php on this host is 8.1.2 and must never be used. Always the full 8.3 path. A command that appears to succeed under 8.1 is not evidence that the application works.
open_basedir means the application can read /var/www/vhosts/arxd.org/ and /tmp/ and nothing else. A script that reaches outside that boundary fails with a permission error that looks like a missing file.
2. Code deployment
The repository root is /var/www/vhosts/arxd.org; the web root is httpdocs/. That layout is why .env, storage/ and the agent signing key sit inside the document root, protected by .htaccess rewrite rules rather than by being outside it.
Deployment is a git operation followed by a permission pass:
cd /var/www/vhosts/arxd.org
git status # never deploy on top of an unclear tree
git pull --ff-only
Then, because files written by tooling arrive owned by root:
cd httpdocs
chown -R arxd.org_lzf2t1q5l6r:psacln .
Use -R sparingly. On a healthy tree only the files that were just written need it, and a blanket -R over storage/ can disturb files the worker is holding.
What must survive a deploy
.env— never overwritten, never committed.storage/— logs, the agent signing key, uploads.- Anything under
httpdocs/downloads/that is generated from a build artefact.
3. Database changes
Migrations are numbered SQL files in httpdocs/migrations/, applied in order and recorded in the migrations table with a batch number.
cd /var/www/vhosts/arxd.org/httpdocs
/opt/plesk/php/8.3/bin/php tools/console.php migrate:status
/opt/plesk/php/8.3/bin/php tools/console.php migrate
Rules that are not negotiable:
- Write migrations additively. Add a column, backfill, then stop using the
old one in code. Drop it in a later migration once nothing reads it.
- Never apply SQL by hand. Data written by the
mysqlclient changes the
database but leaves the ledger saying PENDING, so migrate:status stops being a truthful answer to "what is the schema". If it happens anyway, migrate will re-run the file — which is why migration files are written to be idempotent — and the ledger catches up.
- Back up before a schema change, not after.
MYSQL_PWD="$(cat /etc/psa/.psa.shadow)" \
mysqldump -uadmin ARXD > /var/www/vhosts/arxd.org/backups/ARXD-$(date +%F-%H%M).sql
- Check the data, not just the exit code. A migration that ran in 2 ms and
updated zero rows is indistinguishable from success until you SELECT the affected table.
4. File permission model
| Path | Mode | Why | | --- | --- | --- | | .env | 600 | Contains the DB password and every provider key | | storage/logs/ | 750 | Exception traces can quote request data | | storage/keys/ | 700 | The agent artefact signing key | | storage/deployments/ | 750 | Packed website archives waiting for an agent to collect them; created on demand with 0750 by RemoteDeploy::storageRoot() | | downloads/ | 755 | Public artefacts | | Application .php | 644 | Read by the web user only |
If a page returns 500 immediately after a deploy, check ownership before checking code. A root-owned PHP file that the web user cannot read produces the same blank failure as a syntax error.
5. Web server rules
.htaccess does four things:
- Rewrites everything that is not a real file to
index.php. - Denies direct access to
.env,storage,docs,migrations,tests,
tools, app, routes and views. These directories must never be readable over HTTP even though they live under the document root.
- Sends a
301from/docsto/documentation— the rendered page — before
the deny rule, so the address works while the directory stays closed.
- Sets security headers for responses the application does not construct.
Verify after any .htaccess edit:
curl -o /dev/null -s -w '%{http_code}\n' https://arxd.org/.env # 403
curl -o /dev/null -s -w '%{http_code}\n' https://arxd.org/docs # 301
curl -o /dev/null -s -w '%{http_code}\n' https://arxd.org/docs/architecture.md # 403
curl -o /dev/null -s -w '%{http_code}\n' https://arxd.org/documentation # 200
6. Cron
* * * * * cd /var/www/vhosts/arxd.org/httpdocs && /opt/plesk/php/8.3/bin/php tools/worker.php >> storage/logs/worker.log 2>&1
The worker is idempotent and concurrency-safe, so a slow run and the next tick can overlap without corrupting state.
tools/arxd-logrotate rotates logs; tools/arxd-watchdog.sh alerts when the worker has stopped. The watchdog matters more than the log rotation: a stopped worker does not page anyone by itself, it just quietly stops evaluating monitors and expiring commands.
Confirm the worker is alive before believing any monitoring page. A dashboard fed by a dead worker shows the last state it knew, which looks like calm.
A queued build job sits in queued until a worker claims it, so the same cron tick is what runs builds. If builds appear to hang, the answer is almost always that the worker is not running — check developer:status for a running job with an old claimed_at before looking anywhere else.
The incident sweep
Sweep 4b in tools/worker.php closes incidents nobody closed. It is registered directly after wake_suppressed, which is deliberately after monitor evaluation in the same tick: the sweep acts on what this cycle just observed rather than on the state two minutes ago.
It only ever moves an incident toward closing, and only in two steps. When none of an incident's linked alerts is still firing, an investigating or identified incident moves to monitoring with a sentence saying so — a condition that stopped is not the same as a cause that was found. Only an incident already in monitoring is eligible to be resolved, after QUIET_MINUTES (30) with nothing firing and no updates, and that resolution is written into the timeline attributed to the platform. It never reopens anything, never edits a human's note, and never touches an incident with no linked alerts at all: one a person opened by hand has no monitoring behind it and stays open for a person to close.
When an incident will not close, check in this order:
- Is the worker running? No sweep means nothing closes except by hand.
- Have the linked alerts actually cleared? The sweep reads
alerts, not the
incident's own description of itself.
- Has it been quiet for the full window, and has it already passed through
monitoring? A failure that just stopped is still monitoring for the next thirty minutes by design — that gap is the difference between "recovered" and "flapping".
The sweep is reported as incidents N rows in --verbose output. incidents 0 rows means it ran and had nothing to move, which is the normal steady state on an estate with no open incidents — it is not a missing registration.
The remote-deployment sweep
Sweep 5b in tools/worker.php clears up publishing to servers ARXD does not own. It is registered immediately after expire_commands, and the order is the whole point: a command that has just timed out is exactly how a remote_deployments row would otherwise stay transferring forever, and the sweep can only see the expiry once it has happened.
It does two things per tick. It fails rows whose command ended failed|timeout|cancelled|expired, and rows still queued with no command_id after an hour — a deployment that was never turned into a command is not going to become one. It also deletes up to 200 archives older than ARTEFACT_TTL_HOURS (12), setting artefact_path to NULL and stamping artefact_purged_at.
The row is kept when the archive is purged. A customer's deployment history is the record of what they asked for and what the agent reported, and deleting the zip removes a copy of their website without removing any of the history. An agent that tries to fetch a purged archive gets a 404 not_available with the reason, which the agent reports as a failed command rather than retrying forever.
storage/deployments being empty is normal. It means nothing is currently in transit, not that publishing is broken. To tell the two apart, read the table: SELECT status, COUNT(*) FROM remote_deployments GROUP BY status should show no row sitting in queued or transferring for more than an hour. If one is, the worker is not running.
7. Verifying a deploy
Run all of this after every deploy. It takes under a minute and catches the failures that otherwise surface as a customer email.
cd /var/www/vhosts/arxd.org/httpdocs
PHP=/opt/plesk/php/8.3/bin/php
# 1. Syntax
$PHP -l app/bootstrap.php
# 2. Ledger
$PHP tools/console.php migrate:status | grep -i pending # expect nothing
# 3. Suites
$PHP tests/marketing_test.php
$PHP tests/journey_test.php
$PHP tests/exposure_pages_test.php
# 4. Live surface
for p in / /platform /website-studio /developer-hub /autonomous /documentation /pricing /about /register; do
printf '%-18s %s\n' "$p" "$(curl -s -o /dev/null -w '%{http_code}' https://arxd.org$p)"
done
# 5. Errors
grep -c "$(date +%Y-%m-%d)" storage/logs/exception.log
# 6. Background work actually ran this cycle
$PHP tools/worker.php --verbose
$PHP tools/console.php developer:status
The worker's verbose output ends with a builds: line. If the line is absent the sweep is not registered; if it says 0 run, 0 passed, 0 failed there was simply nothing queued. Those are different problems and the line distinguishes them.
Look for an incidents line the same way. incidents 0 rows means the sweep ran and had nothing to close; no line at all means the registration is gone, and every incident recovered by a passing check will stay open until someone resolves it by hand.
A silent CLI run is not a pass. Core\ErrorHandler installs an HTML error page and can exit 0 on an uncaught exception, so a suite that prints nothing may have crashed. Look for the summary line. If there is none, re-run without a pipe and then read storage/logs/exception.log.
8. Rollback
| What went wrong | How to get back | | --- | --- | | A code change | git revert the commit, pull, chown. Deploys are atomic per commit. | | A migration that added a column | Leave the column. Revert the code that reads it. Dropping a column to undo a deploy risks data you cannot recover. | | A migration that wrote data | Restore the affected rows from the backup taken in §3, then re-run migrate:status. | | A broken .htaccess | git checkout -- httpdocs/.htaccess, then re-run the four curl checks in §5. | | A bad website build | The previous deployment is retained as the rollback target; re-point the website at it from the console. The deployed artefact is portable, so this is a pointer move, not a rebuild. | | A stopped worker | Nothing to roll back — run tools/worker.php in the foreground and read the sweep results. |
There is no staging environment to rehearse in, so the sequence is always: back up, change the smallest possible thing, verify, and only then continue.
9. Go-live gate
Before the platform is considered live for a paying customer:
- [ ]
migrate:statusshows nothing pending - [ ] All suites green, with summary lines read
- [ ] The worker has run within the last five minutes
- [ ]
paypal:checkreports the live configuration truthfully - [ ]
/api/healthreturns200withdatabase: ok - [ ]
storage/logs/exception.loghas no entry for today's date - [ ] The nine public routes return
200with distinct titles - [ ]
.envand the signing key are readable only by the application user