SOP: Restart, Verify and Diagnose a LAMP + Gunicorn Box
The commands, in the order you actually need them, for a box running Apache in front of a Python app.
Restart and reload
sudo systemctl reload apache2 # config changes - no dropped connections
sudo systemctl restart apache2 # when reload is not enough
sudo systemctl status apache2 # is it up, and what did it last say
sudo apache2ctl configtest # ALWAYS before restarting
Reload before restart. A reload re-reads configuration without dropping connections; a restart drops them. configtest first, always — a syntax error found by restart is a syntax error found by an outage.
For the app itself:
sudo systemctl restart aios
sudo systemctl status aios
sudo journalctl -u aios -n 100 --no-pager
Enable a module
apache2ctl -M | grep headers # is it loaded
sudo a2enmod headers
sudo systemctl reload apache2
What is actually listening
sudo ss -tlnp
This is the answer to "is my app port exposed", and it is the only trustworthy one. Trying to reach http://your-site:8000 from a browser tab on an HTTPS page gets blocked as mixed content before the request leaves the machine — three clean-looking failures that prove nothing at all.
Read the bind address. 127.0.0.1:8000 means loopback only and Apache is the sole route in. 0.0.0.0:8000 means the internet can reach your app directly.
Where the errors are
sudo tail -n 100 /var/log/apache2/error.log
sudo tail -f /var/log/apache2/access.log
A PHP fatal lands in the Apache error log, not in the response. A 500 with an empty body almost always means the script died before it produced output — a failed require, an uncaught exception at the top of the file. The response tells you nothing; the log has the line number.
Permissions after a deploy
sudo chown -R www-data:www-data /var/www/html/some/path
sudo chmod 600 /var/www/.env
Secrets get 600 and belong above the docroot, not in it.
A deploy checklist that catches the usual failures
configtestbefore touching the service.- Reload, do not restart, unless you must.
curl -sIthe site and read the headers that came back.- Load one real page and check the console, not just the status code.
- Check the error log even when it looks fine.
The rule worth keeping
Everything in this list answers a question about the running system. That is why they are the commands worth memorising.