# How to clean /var/tmp folder which is now 8 GB in size?

**URL:** https://forum.mautic.org/t/how-to-clean-var-tmp-folder-which-is-now-8-gb-in-size/35422
**Category:** Mautic 5 Install/Upgrade Support
**Created:** [March 31, 2025, 11:25pm UTC](https://forum.mautic.org/t/how-to-clean-var-tmp-folder-which-is-now-8-gb-in-size/35422 "2025-03-31T23:25:32Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ctotech](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ctotech/32/13067_2.png) [@ctotech](https://forum.mautic.org/u/ctotech)
#### Post date: [March 31, 2025, 11:25pm UTC](https://forum.mautic.org/t/how-to-clean-var-tmp-folder-which-is-now-8-gb-in-size/35422/1 "2025-03-31T23:25:32Z")

</div>

**Your software**  
My Mautic version is: 5.1.1  
My PHP version is: 8.1  
My Database type and version is: MariaDB 10

**Your problem**  
My problem is:

/var/tmp folder is \>8GB in storage

Is it safe to delete the contents when in maintenance mode?

---

<div class="post-metadata">

### Author: ![ctotech](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ctotech/32/13067_2.png) [@ctotech](https://forum.mautic.org/u/ctotech)
#### Post date: [April 27, 2025, 12:46am UTC](https://forum.mautic.org/t/how-to-clean-var-tmp-folder-which-is-now-8-gb-in-size/35422/2 "2025-04-27T00:46:03Z")

</div>

Hi, the issue seems to be /tmp/var/twig folder, where it is full of PHP files with twig compiled email templates that had values interpolated.

It is up to 15GB now, majority is over 30 days old.

Is it safe to delete the files that are over 7 days old?

And is there a console command to clear this cache periodically? When I run console command “cache:clear”, it does not do anything to the /tmp/var/twig folder.

---

<div class="post-metadata">

### Author: ![ricfreire](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ricfreire/32/14973_2.png) [@ricfreire](https://forum.mautic.org/u/ricfreire)
#### Post date: [April 27, 2025, 1:42am UTC](https://forum.mautic.org/t/how-to-clean-var-tmp-folder-which-is-now-8-gb-in-size/35422/3 "2025-04-27T01:42:24Z")

</div>

Hi @ctotech,

Let me clarify:

- `mautic:cache:clear` clears the cache from `var/cache`.
- `mautic:maintenance:cleanup` cleans up anonymous visitors, LP hits, and old audit log entries.

If most of your cache is coming from the `/tmp/var/twig` folder it is likely due to **compiled Twig templates** generated for emails. These templates are compiled dynamically when you send emails, with variables replaced by actual values (first/last names for example).

Regarding deleting them: it could be safe to delete it, however **be cautious** if you’re doing it automatically, especially if there are active campaigns running. I recommend waiting at least until the campaign finishes before clearing those PHP files!

Hope I helped.  
Best regards,  
Ricardo

---

<div class="post-metadata">

### Author: ![ctotech](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ctotech/32/13067_2.png) [@ctotech](https://forum.mautic.org/u/ctotech)
#### Post date: [April 27, 2025, 4:38pm UTC](https://forum.mautic.org/t/how-to-clean-var-tmp-folder-which-is-now-8-gb-in-size/35422/4 "2025-04-27T16:38:21Z")

</div>

Hi @ricfreire,

Thanks for the lead.

Is there a way to distinguish between which files are associated to Transactions vs. Segment emails?

So far, we have only been sending Transactional emails, but are intending to start using Campaigns soon, so the auto-delete at 7 days may be problematic.

I may need to write a PHP script for a cron task to handle the clean-up of /tmp/var/twig files, based on left-joining the column values to find the non-active Campaign twig cache files only.

Also, if I delete the /tmp/var/twig files, won’t Mautic just recreate them if still needed?

Thanks for your guidance🙏

---

<div class="post-metadata">

### Author: ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)
#### Post date: [April 28, 2025, 4:35am UTC](https://forum.mautic.org/t/how-to-clean-var-tmp-folder-which-is-now-8-gb-in-size/35422/5 "2025-04-28T04:35:48Z")

</div>

Hello!

The twig files should not be associated with your emails. Everything regarding emails are stored in the DB in your email\_stats table. The email\_stats table is using the email\_id found in the emails table, which also contains an email\_type column. This column can tell you if an email is transactional or segment email.

Recreating your cash is independent from your var/tmp.

Joey

---

<div class="post-metadata">

### Author: ![ctotech](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ctotech/32/13067_2.png) [@ctotech](https://forum.mautic.org/u/ctotech)
#### Post date: [June 10, 2025, 11:48pm UTC](https://forum.mautic.org/t/how-to-clean-var-tmp-folder-which-is-now-8-gb-in-size/35422/6 "2025-06-10T23:48:21Z")

</div>

Hi, I’m looking to better understand this issue with `/tmp/var/twig` files creating so much cache.

So for context:

- we have ~10 Transactional emails, ie. “confirm your email”, “reset password”, “you have a new message waiting”, etc.
- these emails are sent by the website to one recipient, the website includes a list of variables interpolated into the email template (ie. username, confirmation URL).
- once sent, there should no longer be a cache of this twig template, because it was a one-time use (we also never use the “view email in browser” links).

Now we are starting to use Perpetual Campaigns which will be automated and interpolated with Contact field values:

- these are “Segment” emails (not Transactional).
- these will have Contact field values interpolated into the email template.
- each email in the campaign is only sent once per recipient.

Currently, I setup a cron task which deletes all files in `/tmp/var/twig` that are more than 7 days old.

But @ricfreire, you are saying, if I continue using this cron task, it may delete a twig template file that is required by the active Campaign, which could send a Segment email that depends on one of these twig files…?

Looking at one of these twig files, it’s a \*.php file that includes PHP class and methods, and one of the methods `doDisplay(...)` returns the HTML body of the email, which looks like it has already interpolated the values for the specific Contact (ie. links have been replaced with Mautic tracking links).

Are you sure these files need to be used more than once? These files need to persist after the email has already been sent…?
