Uploading site updates file-by-file directly over live production directories creates subtle race conditions: a user requesting the homepage during a 10-second SFTP transfer can receive updated HTML pointing to CSS or assets that have not landed yet, or receive a partially written file.
1. Stage Everything Outside the Public Document Root
A clean deployment script uploads the entire artifact batch into an isolated temporary staging folder (~/deploy-stage-<timestamp>), runs syntax checks (php -l, nginx -t) on staged configs first, and archives a compressed rollback snapshot before modifying /www/wwwroot/.
2. Order Writes: Assets & APIs Before Entry-Point HTML
When promoting staged files with install -m 644 -o www -g www (which unlinks/replaces cleanly with deterministic permissions):
- Promote backend PHP handlers, images, stylesheets, and sub-pages first.
- Run
nginx -t && nginx -s reloadif routing/rewrite rules changed. - Promote
index.htmlandsitemap.xmllast so no crawler ever sees links to files not yet in place.
3. Automated Post-Deploy Verification
Never finish a deploy script on upload success alone. Verify HTTP status codes across critical routes (/ 200, /about.html 200, /contact.html 200, /ads.txt 200, removed paths 404), verify JSON API responses, and record exact SHA-256 digests in a local deployment manifest for auditability.
4. Handling Rollbacks Safely When Something Breaks
Because the pre-deploy script saves a private compressed tarball of the previous live root and Nginx vhost inside a restricted backup directory (/www/backup/<site>/<timestamp>/ with chmod 700), rolling back a regression takes one atomic command:
# Verify tarball integrity and restore prior static files + vhost
tar -xzf /www/backup/orangevpn-portfolio/<timestamp>/site.tar.gz -C /www/wwwroot/orangevpn.com.ph
nginx -t && nginx -s reload
Keeping deployment tooling idempotent, verifying every newly created file via HTTPS immediately after reload, and cleaning temporary staging directories prevents stale backup clutter from leaking onto public webroots.