Commands to troubleshoot web servers and databases.

A guide offering some common troubleshooting techniques for when you can't connect to your remote web server.

Please note that you will need to use sudo in front of the commands if you are not root.

Check if the service is running

systemctl status <service name> -l

If it is not running you can try restarting the service.

systemctl restart <service name>

If you have recently rebooted the service and it did not restart automatically, then it may not be enabled, causing it not to start at boot.

Enable services

systemctl enable <service name>

The service may be listen on the wrong port or a port you didnt expect. To view which address and ports a service is bound on, run this command:

ss -atpu

Check to see if IPv4 or IPv6 is bound. You might be trying to connect to IPv6 and it is not bound.


Analyse Logs

When you get really stuck, logs can be the source of truth so it is a good idea to review them. Your system logs can be found by the following ways:

systemd systems command - journalctl
Ubuntu & Debian - /var/log/syslog
CentOS - /var/log/messages

Logs can be hard to read. If you come accoss something that you do not know what it means, plugging the log into google can bring back some good results.

Web Server Logs

Here are some commands to run on your web server which will help you find logs:

<Apache> grep ErrorLog -r /etc/apache2
<Nginx> grep error_log -r /etc/nginx

Here is a list of frequent error codes that you might come accross:

  • 401 Unauthroised / 403 Forbidden > User does not have permission
  • 404 Not Found > The request could not be found by the web server
  • 500, 502, 503, 504 > The resources required for the request didnt respond as expected. e.g. database not running

Firewall Rules

Your firewall might be giving you trouble. You can review your current firewall rules for IPv4 & IPv6:

iptables -L
ip6tables -L

If you are using UFW you can see the status by typing:

ufw status

Troubleshoot Database

The most common reason a database might not respond is if the disk is full. To check how much diskspace you are using:

df -h

If the disk is full, you have a few options to resolve the issue.

  1. Free up space on your disk by locating and removing files, use a tool like ncdu.
  2. Resize your disk to take advantage of unallocated space.
  3. Upgrade your storage if using VPS or mount an extra disk.