Finding out what is wrong
The lab sheets tell you what to type when everything works. When it does not, these commands tell you why, so you can fix it instead of starting over.
1. Read the error message
Most errors already say what is wrong. Look for:
- A number:
ERROR 1045,HTTP 404,Errno 13. Search the wiki or ask the assistant with that number. - A file or name:
/dev/ttyACM0,'Nypuser'@'localhost',sql-data.html. Check it exists and is spelled exactly the same (Linux is case-sensitive). - "Permission denied": you need
sudo, or the file belongs to someone else. See files and permissions. - "not found" / "No such file": wrong name, wrong folder, or not installed.
In Python, read the last line of the traceback first, then the line above it that names your file.
2. Is the service running?
systemctl status apache2 # or mariadb
active (running) in green is good. failed or inactive means it stopped: the last lines of the status usually say why. For the full story:
sudo journalctl -u apache2 -n 30 --no-pager # last 30 log lines of one service
sudo journalctl -xeu mariadb # jump to the end, with explanations
3. Check the config before restarting
A typo in a config file stops the whole service from starting. Test first:
sudo apache2ctl configtest # "Syntax OK" means safe to restart
For MariaDB, a bad config shows up in sudo journalctl -u mariadb as unknown variable or Found option without preceding group.
4. Look at the log files
| Program | Log |
|---|---|
| Apache (and PHP errors on web pages) | sudo tail -n 30 /var/log/apache2/error.log |
| Apache: which pages were requested | sudo tail -n 30 /var/log/apache2/access.log |
| MariaDB | sudo journalctl -u mariadb -n 50 |
| Everything | sudo journalctl -n 50 |
tail -f instead of tail -n 30 keeps watching: refresh the web page and see the error appear live. Press Ctrl+C to stop.
5. Is it listening, and where?
sudo ss -tlnp
Lists every program waiting for connections. Look for:
| Port | Program | If it shows 127.0.0.1: |
|---|---|---|
| 80 | apache2 | |
| 3306 | mariadbd | only the Pi itself can connect (normal) |
| 5000 | python (Flask) | Flask was started without host='0.0.0.0', so other devices cannot open it |
| 22 | sshd |
If the port is not in the list at all, the program is not running.
6. Is the Arduino connected?
ls /dev/ttyACM* /dev/ttyUSB* # does the port exist?
sudo dmesg | tail -n 20 # what Linux saw when you plugged it in
groups # is "dialout" in the list? (needed to open the port)
dmesg shows cdc_acm ... ttyACM0: USB ACM device when the Arduino is detected. Nothing new appearing means a charge-only cable or a bad USB port.
7. Who am I, and where am I?
whoami # pi or root?
pwd # which folder?
ls -l # who owns these files?
Many "it worked yesterday" problems are a file saved as root (with sudo nano) that your normal user or Apache can no longer read or write.
8. Change one thing at a time
Change one thing, test, then change the next. If you change five things and it starts working, you do not know which one fixed it, and if it gets worse, you do not know which one broke it. Before editing a config file, keep a copy:
sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.bak