Skip to main content
+44 7575 472931[email protected]
HostaccentKnowledge BaseHosting, websites, SEO, and growth

How to Check Server Logs in Linux and Find the Real Error

How to check server logs in Linux: run journalctl -u, tail -f the Nginx or Apache error log, then grep for the first error, not the last. Updated for 2026.

VPSBeginner GuideSecurity
How to check server logs in Linux using journalctl, tail -f and grep to trace the first real error behind a site outage

A 500 error, a service that won't start, a site that dies at 2 a.m.: the dashboard tells you something broke, and only the logs tell you what. This guide shows how to check server logs in Linux the way our support engineers do it on live servers while resolving 20 to 30 client issues every day, so you can find the real error yourself instead of guessing.

Quick Answer: Run sudo systemctl status <service> for the latest lines, then sudo journalctl -u <service> --since "30 minutes ago" for its recent history. For website errors, open the Nginx or Apache error log with sudo tail -n 100, follow it live with tail -f while you reproduce the problem, and filter with grep -i error. The real cause is usually the first error in the time window, not the last.

Last verified: October 2026: Ubuntu 26.04 LTS, Ubuntu 24.04 LTS (rsyslog 8.2312), Debian 13 (journald only by default)

Where Linux Server Logs Live in 2026 (journald vs /var/log)

Modern Linux keeps logs in two places at the same time. The systemd journal, read with journalctl, captures output from every service and from the kernel. Separately, plain text files under /var/log are written by rsyslog and by applications like Nginx, Apache and MariaDB that manage their own log files.

That split catches people out. As of October 2026, Ubuntu 24.04 LTS still installs rsyslog, so /var/log/syslog and /var/log/auth.log exist on a fresh server. Debian 12 and Debian 13 do not install rsyslog by default, so a new Debian VPS has no /var/log/syslog at all, and old tutorials that tell you to run cat /var/log/syslog simply fail there.

On a newer release such as Ubuntu 26.04, check rather than assume: dpkg -l rsyslog tells you in 1 second whether the text logs are being written.

What you're debuggingUbuntu / DebianAlmaLinux / Rocky / RHELcPanel server
General system messages/var/log/syslog or journalctl/var/log/messages/var/log/messages
SSH logins and sudo/var/log/auth.log/var/log/secure/var/log/secure
Nginx errors/var/log/nginx/error.log/var/log/nginx/error.log/var/log/nginx/error.log (if ea-nginx is installed)
Apache errors/var/log/apache2/error.log/var/log/httpd/error_log/etc/apache2/logs/error_log
PHP-FPM/var/log/phpX.Y-fpm.log/var/log/php-fpm/error.log/opt/cpanel/ea-phpXY/root/usr/var/log/php-fpm/error.log
MariaDB / MySQL/var/log/mysql/error.log/var/log/mariadb/mariadb.log/var/lib/mysql/<hostname>.err
Mail/var/log/mail.log/var/log/maillog/var/log/exim_mainlog
Kernel and OOM killsjournalctl -kjournalctl -kjournalctl -k

If a path in the table doesn't exist, the logs probably went somewhere else rather than nowhere. Across the 4,000+ site migrations Hostaccent has handled since 2016, the log mistake we see most after a move is assuming the new server writes to the same paths as the old one. A site that moves from a cPanel box to a plain Ubuntu VPS keeps its bugs but loses its familiar error_log locations. On panel servers the layout shifts again, and our guide to finding the cPanel error log maps those paths one by one.

Pro Tip: Run ls -lt /var/log | head -15 right after the problem happens. The file modified in the last minute is very often the one recording it, which saves you guessing which of 40 log files matters.

How to Check Server Logs in Linux With journalctl

Start with systemd, because it has already captured the last output of every service before it failed. Three commands cover most cases.

bash
sudo systemctl status nginx
sudo journalctl -u nginx -n 100 --no-pager
sudo journalctl -u nginx --since "1 hour ago" -p err

The first shows whether the service is running plus its last 10 log lines, which is often enough on its own. The second prints the last 100 lines for that one unit without opening a pager. The third limits the output to error-level messages from the past hour.

On a systemd server, journalctl -u <service> --since "1 hour ago" is the fastest single command for finding out why a service failed, because it filters the whole journal down to one unit and one time window. Adding -p err keeps only error-level messages, which on a busy server typically cuts thousands of lines down to a handful.

When you know exactly when things broke, give it a window: sudo journalctl --since "2026-10-30 02:10" --until "2026-10-30 02:20". Leave out -u and you get every service merged into one timeline, which is something separate text files can't give you.

What does journalctl -xe actually show?

-x adds explanatory catalog text to messages that have it, and -e jumps to the end of the journal. It's the command systemd itself suggests when a service fails to start. The catch is that it shows the end of the entire journal, so on a busy server the failure you care about may already be buried under cron and SSH noise. Run sudo journalctl -xeu nginx instead and the same view is limited to the unit that failed.

Kernel messages, OOM kills and crashes

If a process vanished with no error in its own log, the kernel probably killed it. sudo journalctl -k | grep -i "out of memory" shows out-of-memory kills, and if you find them, our walkthrough on why a VPS runs out of RAM covers the fix. After an unexpected reboot, journalctl --list-boots lists previous boots and sudo journalctl -b -1 -e opens the end of the last one, right before it went down.

That only works if the journal is persistent. When /var/log/journal doesn't exist and storage is left on auto, the journal lives in memory and disappears at every reboot. Create it with sudo mkdir -p /var/log/journal and restart systemd-journald. The full option list is in the official journalctl documentation.

Pro Tip: Check journalctl --disk-usage once in a while. A journal left unbounded can grow past several GB, and setting SystemMaxUse=500M in /etc/systemd/journald.conf keeps it in check without losing recent history.

Reading Web Server and PHP Logs With tail -f and grep

Web servers, PHP and databases write their errors to their own files, so this is where tail and grep do the heavy lifting. Begin with the most recent lines:

bash
sudo tail -n 100 /var/log/nginx/error.log
sudo tail -n 100 /var/log/apache2/error.log

Follow a live log with tail -f

The tail -f live log trick works because most web errors can be reproduced. Start following the error log, reload the failing page once, and the new lines that appear in the next 2 or 3 seconds are almost certainly tied to your request. It filters out hours of unrelated history without writing a single search pattern.

bash
sudo tail -f /var/log/nginx/error.log /var/log/apache2/error.log

You can follow several files at once, as above, and press Ctrl+C to stop. Use tail -F (capital F) if the log might rotate while you watch, because it reopens the file under its new name. Each server documents its own format: see the Apache HTTP Server log files reference and the Nginx error_log directive for what each field means and how to raise the log level.

grep for errors without drowning in output

To grep for errors in a log file, search case-insensitively and keep only the newest matches:

bash
sudo grep -i "error" /var/log/apache2/error.log | tail -20
sudo grep -i -B 5 -A 10 "fatal" /var/log/apache2/error.log
sudo zgrep -i "fatal" /var/log/apache2/error.log.*.gz
sudo grep -c " 502 " /var/log/nginx/access.log

-B 5 -A 10 prints 5 lines before and 10 after each match, which is usually where the explanation sits. zgrep searches rotated, compressed logs without unpacking them. The last line counts how many requests returned a 502.

The access log tells you which requests failed, and the error log tells you why. With the default combined format, sudo awk '$9 ~ /^5/' /var/log/nginx/access.log | tail -20 lists the latest 5xx responses so you can match their timestamps against the error log. If Nginx reports connect() failed (111: Connection refused) while connecting to upstream, PHP-FPM is down or listening somewhere else, and our 502 Bad Gateway Nginx fix works through exactly that case.

PHP is the usual blind spot. With display_errors off (correct for production) and log_errors also off, fatal errors are written nowhere at all. Turn log_errors on and set an error_log path, as described in the PHP error-handling configuration docs. WordPress adds its own option: WP_DEBUG_LOG writes to wp-content/debug.log.

Professional help available

Still working through this server issue?

Send the symptoms, error output, and what you have already tried. We can work with Hostaccent services or infrastructure hosted with another provider.

Request server helpHow server support worksHosted elsewhere? One-time paid support is available after scope and price confirmation.

Finding the Real Error: The Upstream Walk

The real error is almost always the first one, in the deepest layer, inside the minute when the failure started. Finding it is a routine rather than luck.

We call that routine the Upstream Walk. It's the method Hostaccent's engineers run on the 20 to 30 client issues they resolve each day, and it has four steps:

  1. Pin the timestamp and the time zone. Note when the error happened and run timedatectl to see the server's zone. Cloudflare and many PHP setups log in UTC while the journal shows local time, and a 6-hour offset can send you reading the wrong part of the file.
  2. Start where the error surfaced. A 502 in the browser means the Nginx error log. A Cloudflare 52x error means the front web server on your origin. "Error establishing a database connection" means MariaDB.
  3. Walk one layer inward per step. Nginx, then Apache, then PHP-FPM, then MariaDB, then the kernel with journalctl -k. At each layer, read the 2 minutes before your timestamp.
  4. Stop at the first error that explains everything after it. That line is the cause. Everything below it is fallout.

Why is the last line in the log almost never the real problem?

Failures cascade. Once MariaDB stops accepting connections, every PHP request fails, and the log fills with hundreds of identical downstream errors. The line at the bottom is simply the latest victim. Scroll up to where the pattern starts.

The first error in the deepest layer is usually the root cause of a Linux server failure. When MariaDB, PHP-FPM and Nginx all log errors inside the same 60-second window, the database error that appears first explains the PHP and Nginx errors that follow it, so fixing that single line typically clears the rest.

A pattern we see often on WooCommerce stores goes like this. Nginx logs upstream timed out, the PHP-FPM log says server reached pm.max_children setting, and the MariaDB slow query log shows one unindexed query taking several seconds. Raising max_children treats the symptom. Fixing the query fixes the outage. If MariaDB is dropping connections outright, start with MySQL Server Has Gone Away: causes and the fix, and if pages are slow rather than broken, the same walk applies to fixing high TTFB in WordPress.

Insider Insight: Before reading any single file, run sudo journalctl --since "10 minutes ago" -p warning with no unit filter. Services that log to the journal appear side by side in time order, and the first warning in that list often points you at the right layer straight away.

Common Log-Reading Mistakes (and What to Do When Logs Are Empty)

Most "the logs show nothing" moments come from permissions, time zones, rotation or a full disk, not from a missing log. Check these before you assume the server stayed silent.

Reading without sudo. Run journalctl as a normal user and it quietly shows only your own entries, with no error to warn you. Use sudo, or add your user to the adm or systemd-journal group.

Looking at the wrong file. Logrotate renames error.log to error.log.1 daily or weekly, then compresses older copies. Yesterday's incident lives in .1, and last week's is in a .gz file that only zgrep or zcat can read.

A full disk. When / hits 100%, services can't write logs at all, so the outage erases its own evidence. Check df -h for space and df -i for inodes, then find the culprits with sudo du -sh /var/log/* | sort -h | tail.

Deleting a large log file with rm while Nginx or Apache still has it open does not free any disk space, because the process keeps writing to the deleted file until it restarts. On a full disk, sudo truncate -s 0 empties a 5 GB log in place and releases the space at once, which makes it the safer emergency move.

No root at all. On shared hosting you can't run journalctl, but cPanel's Errors and Raw Access screens show your own site's logs. If those point at CPU or memory caps, read shared hosting resource limit exceeded: causes and fix.

The short version

  • Ask systemd first: systemctl status, then journalctl -u <service>.
  • Read the service's own file next, with tail -n 100 or tail -f while you reproduce the error.
  • Filter with grep -i, add -B and -A for context, and use zgrep for rotated logs.
  • Walk inward from the layer that showed the error, and trust the first error, not the last.

Your Next Step: A Server Where the Logs Get Read With You

You now know how to check server logs in Linux: journal first, then the service's own file, then walk inward to the first error. You can run that routine yourself at 2 a.m., or run your sites on a VPS where the engineers who use it daily answer the support line. Hostaccent's Standard plan at $12.00/mo gives you full root access, NVMe storage and free 30 Gbps DDoS protection, backed by 24/7 support and a 30-day money-back guarantee. It also renews at the same $12.00/mo. One honest caveat: no control panel licence is included, so budget for cPanel or Plesk separately if you want one. Start on the Standard VPS plan at $12.00/mo.

Frequently Asked Questions

How to check server logs in Linux without root access?

Without root, journalctl shows only entries from your own user, so you need membership in the adm or systemd-journal group to read system-wide logs. Ask whoever manages the server to add you. On shared hosting, root is never available, but cPanel's Errors and Raw Access tools display your own site's error and access logs, and PHP usually writes an error_log file inside your site's folder that you can open directly.

What is the difference between journalctl and /var/log?

journalctl reads the systemd journal, a structured binary log that collects output from every service and the kernel and lets you filter by unit, priority and time. The /var/log directory holds plain text files written by rsyslog and by applications such as Nginx, Apache and MariaDB. Many servers run both at once. Use journalctl for services and boot problems, and the text files for web server and database detail.

Why is /var/log/syslog missing on my server?

Since Debian 12, rsyslog is no longer installed by default, so Debian 12 and Debian 13 servers write system messages only to the journal and never create /var/log/syslog. Nothing is broken. Run sudo journalctl to read the same messages, or install the rsyslog package if a script or tool such as Fail2ban needs text files. Ubuntu 24.04 still ships rsyslog, so the file exists there by default.

How do I see logs from before the server rebooted?

Run journalctl --list-boots to list the boots the journal remembers, then sudo journalctl -b -1 -e to jump to the end of the previous boot, right before the restart. This only works with persistent journal storage, meaning the /var/log/journal directory must exist. If it doesn't, earlier boots were held in memory and are gone, so create that directory now and restart systemd-journald to keep history next time.

How do I search a log file for a specific error?

Use grep -i "your error text" /path/to/logfile for a case-insensitive search, and pipe it to tail -20 to see only the newest matches. Add -B 5 -A 10 to print lines around each hit, since the explanation often sits just above the error. For rotated, compressed logs ending in .gz, swap in zgrep. With the journal, journalctl -u service --grep "pattern" filters entries the same way.

How long does Linux keep server logs?

Text logs under /var/log are kept according to logrotate rules, which on Ubuntu and Debian commonly rotate weekly and keep around 4 old copies, though each package can set its own schedule in /etc/logrotate.d/. The systemd journal is limited by size rather than days, capped by default at a share of the disk. Set SystemMaxUse or MaxRetentionSec in journald.conf if you need a fixed retention period.

Professional help available

Still not resolved? Let a server specialist take it from here.

Send the symptoms, error output, and what you have already tried. We can work with Hostaccent services or infrastructure hosted with another provider.

  • No hosting transfer required
  • Scope confirmed before paid work
  • No changes before your approval
Request server helpHow server support worksHosted elsewhere? One-time paid support is available after scope and price confirmation.
Reviewed by

Hostaccent Editorial Team

Reviewed for technical accuracy and clarity before publication.

Last updated

Nov 7, 2026

HostAccent Editorial Team publishes practical hosting guides, operations checklists, and SEO-focused tutorials for businesses building international web presence.

Discussion

Have a question or tip about this topic? Share it below — your comment will appear after review.

Your email stays private and is only used for moderation.

Write for the Community

Have a tutorial, tip, or insight to share? Get published on the Hostaccent Blog with your name, bio, and website link.

Become a Contributor

Need a faster setup for this workflow?