Server Administration

Disk Full: Recovering a WordPress Server That Has Run Out of Space

Disk Full: Recovering a WordPress Server That Has Run Out of Space

A full disk is one of the most confusing ways for a WordPress site to fail, because the symptoms rarely mention disk space. You might see “Error establishing a database connection”. Uploads might fail with vague HTTP errors. Logins might stop working because PHP can’t write session files. Caching plugins might throw permission errors. Sometimes the site just shows a blank white page. A WordPress server disk full of forgotten files rarely announces itself in the error messages.

I’ve had clients call in a panic thinking they’d been hacked, only to find a single debug log file had grown to 40 GB. Another time, a backup plugin had been dutifully saving full site backups to the same server every night for two years without ever deleting old ones.

This guide covers how to confirm that disk space is the problem, find what’s using it, recover safely and set things up so it doesn’t happen again.

Confirm the problem

Log in to the server over SSH and check disk usage:

Look at the Use% column for the filesystem that holds your site, usually / or a separate /var or /home partition. If it shows 100% or very close, that’s your problem.

Also check inodes. A filesystem can run out of inodes, the entries that track individual files, even when there’s free space. This happens when something creates millions of tiny files, such as session files or cache fragments.

If IUse% is at 100%, you have too many files rather than too much data.

Find what’s using the space

Start from the root and work down. The du command shows directory sizes:

<code>sudo du -xh / –max-depth=1 2&gt;/dev/nullsort -rhhead -20</code>

The -x flag keeps it on one filesystem. Repeat in the largest directory until you find the culprit. Common places to look on a WordPress server:

  • /var/log, for system, web server and PHP logs
  • /var/lib/mysql, for databases and binary logs
  • The site’s wp-content folder, especially uploads, cache and backup folders
  • /tmp, for leftover temporary files
  • Home directories, where people leave old archives and database dumps

A faster tool for interactive exploration is ncdu, if it’s installed or you can install it:

For large individual files anywhere on the system:

The usual suspects

Over the years, the same causes come up again and again.

Debug logs

If WP_DEBUG_LOG is enabled on a production site, wp-content/debug.log grows forever. A plugin throwing a notice on every page view can add gigabytes a week.

Check its size, then either truncate it or delete it. Truncating keeps the file in place, which avoids permission issues:

Then turn off debug logging in wp-config.php, or at least fix the noisy plugin.

Backups stored on the same server

Backup plugins often save archives to wp-content, sometimes in folders named after the plugin, such as updraft or ai1wm-backups. If retention isn’t configured, they accumulate forever.

Move the backups you need to off-site storage, delete the rest and configure the plugin to store backups remotely with a retention limit. Backups stored on the same server don’t protect you from server failure anyway.

Web server and PHP logs

Access logs on a busy site, or error logs from a misbehaving application, can be large. They usually live in /var/log/nginx, /var/log/apache2 or /var/log/php. If log rotation isn’t set up or isn’t working, they grow without limit.

MySQL binary logs

MySQL and MariaDB can write binary logs for replication and point-in-time recovery. If they’re enabled but never purged, they fill disks. Check /var/lib/mysql for files named mysql-bin.000123 or similar.

Don’t delete these files directly. Use SQL:

Then set an expiry in your MySQL configuration so they’re cleaned up automatically.

Cache folders

Page caching plugins write HTML files to wp-content/cache. Usually that’s fine, but a misconfiguration or a bot crawling infinite URL combinations, like faceted filters with query strings, can create millions of cache files. That’s a common cause of inode exhaustion.

Clear the cache through the plugin, or delete the cache folder contents directly, then fix the configuration so query string variations aren’t cached.

Session files

PHP stores sessions in /var/lib/php/sessions or /tmp by default. If garbage collection isn’t running, old sessions accumulate. Some plugins create sessions for every visitor, including bots, which makes this worse.

Old releases and leftover files

Deployment tools that keep old releases, manual copies like “site-backup-old” and abandoned staging folders all add up. Check the web root and home directories for anything that looks like a duplicate.

Recovering MySQL after a full disk

If MySQL ran out of space while writing, it may have crashed or refused to start. After freeing space:

  1. Start MySQL and check its error log for corruption warnings.
  2. Run a check on the WordPress database:
  1. If any tables are marked as crashed, repair them:

InnoDB tables usually recover on their own when the server restarts. MyISAM tables, still found on older sites, are more likely to need repair.

If the database won’t start at all, don’t start deleting files in /var/lib/mysql. That’s how data gets lost permanently. Look at the error log, free more space and, if necessary, get help from someone experienced with MySQL recovery.

Check that WordPress works

After clearing space and confirming the database is healthy:

  • Load the front end and the admin.
  • Upload a test image.
  • Submit a form.
  • On stores, run a test order.
  • Clear page caches, in case a broken page was cached while the disk was full.

Prevent it from happening again

The fix is rarely difficult. Prevention is mostly about automation.

Set up log rotation

Most Linux distributions use logrotate. Check that your web server and PHP logs are covered. A typical configuration for a custom log location looks like this:

That keeps two weeks of compressed logs and deletes older ones.

If you need WP_DEBUG_LOG on production temporarily, point it to a file outside the web root and include it in logrotate.

Configure backup retention

Every backup should go off-site, and every backup system should have a retention policy. Keep, for example, 14 daily, 8 weekly and 6 monthly copies, and let the tool delete the rest.

Expire MySQL binary logs

In your MySQL or MariaDB configuration:

That keeps three days of binary logs. On MariaDB, the equivalent setting is expire_logs_days.

Monitor disk usage

The best protection is an alert before the disk fills. Server monitoring tools can email or message you when usage passes 80%. Even a simple cron job works:

USAGE=$(df /awk 'NR==2 {print $5}'tr -d '%')
echo "Disk usage on $(hostname) is ${USAGE}%"mail -s "Disk warning" [email protected]

Run it every hour from cron and you’ll know long before anything breaks.

Watch growth trends

A disk that goes from 40% to 60% in a month will be full in two more. Keep a note of usage over time, or use a monitoring tool that graphs it. Sudden jumps usually point to a specific cause worth investigating straight away.

When the disk is simply too small

Sometimes nothing is wrong. The site has grown, and the disk is too small. In that case, the options are:

  • Expand the disk. Most VPS providers let you resize volumes, sometimes without downtime.
  • Move media to object storage so it no longer lives on the server.
  • Move backups and logs to separate storage.

Cleaning up is still worth doing first, so you know how much space the site actually needs.

A quick emergency routine to keep handy

When the alert fires at a bad moment, it helps to have a short routine written down. Mine is: confirm with df -h and df -i, truncate debug.log, delete old on-server backup archives, purge MySQL binary logs older than a few days, clear the page cache folder and restart PHP-FPM to release any deleted files still held open. Those six steps free enough space to bring a site back in most cases, and they buy time to find the real cause calmly.

Write the routine into your server documentation, with the exact paths for each site. In the middle of an outage, nobody wants to remember where a particular backup plugin keeps its archives or which partition holds the database. A WordPress server disk full of logs and old backups is one of the most preventable outages there is.

Frequently asked questions

Can a full disk corrupt my WordPress database?

It can, especially if MySQL was writing when space ran out. InnoDB is fairly resilient, but always check and repair after an incident, and make sure you have a recent backup.

Why does df show free space but I still can’t write files?

You may have run out of inodes, or the filesystem may reserve a percentage of space for root. Check df -i, and check whether a deleted file is still held open by a process using lsof.

How do I find a deleted file that’s still using space?

Run sudo lsof | grep deleted. If a log file was deleted while a process held it open, the space isn’t freed until that process restarts. Restarting the web server or PHP usually releases it.

Should I leave WP_DEBUG_LOG on for troubleshooting?

Only temporarily. Turn it on, reproduce the problem, read the log and turn it off again. On production, it should never run indefinitely.