Tutorials

Free up XenForo disk space by moving attachments off the server

Attachments are usually what fills a forum's disk. How to see what uses your XenForo disk space, shrink new uploads, and move files to cloud storage.

D.C Style · 6 min read
Share on X
On this page

When XenForo disk space runs low, attachments are almost always the reason. Every photo, video and file members upload stays on your server, and a busy forum adds gigabytes a year. You can measure what is using the space, shrink what members upload from now on, and move the files you already have to cloud storage.

Find out what is using your XenForo disk space

XenForo keeps uploaded files in two folders. The full files live in internal_data/attachments, where the web server cannot hand them out directly. The thumbnails live in data/attachments, next to avatars in data/avatars.

If you have SSH access, run this from the folder that holds admin.php:

du -sh internal_data/attachments data/attachments data/avatars

To see every top-level folder sorted by size, use this instead:

du -sh * | sort -h

On most forums the first folder dwarfs everything else. If it doesn't, look for old backups or log files someone left inside the forum folder.

The Admin CP can show you the same picture without SSH. The attachment manager in the Content section switches between the most recent and the largest attachments. You can filter it by file type, member and date.

Shrink what members upload from now on

The settings in Setup > Options > Attachments decide how big new files can be. They don't change files already uploaded, but they slow the growth right away.

  • Maximum attachment image dimensions. XenForo resizes larger images when they are uploaded. A phone photo of several megabytes shrinks to a fraction of that.
  • Image optimization. On XenForo 2.3, this converts uploaded images to WebP, which is usually much smaller than JPEG or PNG.
  • Allowed attachment file extensions. Remove types your members don't need, such as large archives on a forum that never shares them.
  • Video and audio uploads. Videos grow a disk faster than anything else. Allow them only if your members need them, and keep the maximum file size modest.
Tip:

Tell members when you lower a limit. A short notice saves a few confused support questions about uploads that suddenly fail.

Clear out files you no longer need

Sort the attachment manager by size and look at the top of the list. You may find test uploads, duplicate files or attachments whose posts were deleted long ago. Tick the ones you are sure about and delete them.

Warning:

A deleted attachment can't be recovered, and the post it belonged to may no longer make sense without it. Take a backup first and delete only what you have checked.

Cleaning up buys time, but it rarely solves the problem for good. An active forum keeps uploading. The lasting fix for XenForo disk space is to keep the files somewhere else.

Move attachments to cloud storage

Cloud storage is cheaper per gigabyte than server disk, and it grows without a server upgrade. There are two routes.

Amazon S3 or an S3-compatible service

Since XenForo 2.0, the file system is abstracted, so data and internal_data can live on remote storage. XenForo staff explain the setup in their guide to DigitalOcean Spaces and Amazon S3. It means editing src/config.php by hand and running the storage account yourself. That suits admins who are comfortable with server work.

Google Drive, with an add-on

If you already pay for Google Workspace, or you want a setup you can manage from the Admin CP, Google Drive Attachments moves the files to Drive. Members notice nothing: uploads, downloads, thumbnails and the lightbox work as before.

  • Two storage modes. Direct mode sends every upload straight to Drive. Local cache mode writes to your server first, so posting stays instant, then moves files to Drive every three hours.
  • Selective sync. List the file extensions that should go to Drive, one per line. Everything else stays local.
  • Migration for existing files. Move them from the Admin CP or the command line. Uploads run in parallel, and an interrupted run picks up where it stopped.
  • A safe fallback. If Drive is unreachable, XenForo falls back to local storage, so a Google outage never takes the forum down.

It supports Shared Drives as well as personal folders, and needs PHP 8.1 or newer.

Back up and migrate in stages

Whichever route you choose, take a full backup first: the database, data, internal_data and src/config.php. Our guide to backing up your XenForo forum has the commands. Once files live in Drive or S3, back up that storage too.

On a large forum, move the files in batches rather than all at once. With Google Drive Attachments, the command line takes a range of attachment IDs:

php cmd.php xf-rebuild:dcGda-migrateToGoogleDrive --start-id=1 --end-id=50000

After each batch, open a few older threads and check that images and thumbnails still load. Only then add --delete-local, or run --cleanup-local, to free the space. Keeping the local copies until you have checked costs you nothing but a little time.

Questions about moving attachments

Will pages load more slowly from Google Drive?

In direct mode, files load from Google rather than your own disk. That covers more than attachments: avatars and other files in data and internal_data go to Drive too. Local cache mode keeps new uploads on your server for a few hours, so the files people open most right after posting still load locally. Pick direct mode if the goal is an empty disk, and local cache mode if fast posting matters more.

Can I move the files back later?

Yes. Google Drive Attachments migrates in both directions, from the Admin CP or with php cmd.php xf-rebuild:dcGda-migrateToLocal. Run that and let it finish before you uninstall the add-on. Uninstalling on its own does not bring files back from Drive.

Do I still need a bigger server one day?

Perhaps, but for different reasons. Once attachments live elsewhere, uploads stop eating your XenForo disk space. What stays on the server, mostly the database and the code, grows slowly.

What to do next

  1. Run the du commands above, or sort the attachment manager by size, to see where your XenForo disk space goes.
  2. Set a maximum image size and, on XenForo 2.3, switch on image optimization.
  3. Pick a storage route and follow the Google Drive Attachments setup guide if Drive suits you.

A smaller disk also means faster backups and a quicker server move. For more ways to lighten the load, read how to speed up your XenForo forum.