Hereโs a comprehensive and updated tutorial on which files should be cleaned up regularly in a production environment running XAMPP (under /opt/lampp), what each file/folder is, and how to automate cleanup safely.
XAMPP Production File Cleanup Guide
Keeping Your /opt/lampp Environment Healthy
1. Why Regular Cleanup Is Important
- Performance: Old logs and cache files fill up disk space and slow down the system.
- Security: Sensitive info in old logs can be a risk if not managed.
- Reliability: Overfilled disk can cause XAMPP/MySQL/Apache to crash or refuse new data.
2. Key Locations in /opt/lampp to Clean
The typical XAMPP folder structure on Linux (like /opt/lampp) includes:
/opt/lampp/logs/โ Apache and XAMPP logs/opt/lampp/apache/logs/โ Apache server logs/opt/lampp/mysql/data/or/opt/lampp/var/mysql/โ MySQL data and logs/opt/lampp/php/logs/โ PHP logs/opt/lampp/temp/or/opt/lampp/tmp/โ Temporary files/opt/lampp/htdocs/โ Website files (may have user/app caches, uploads, sessions)- Any
storage/directories for frameworks like Laravel
3. What Files Should Be Cleaned Regularly?
Below are the files and folders to clean, with what they do and how to handle them safely:
A. Apache Log Files
- Location:
/opt/lampp/logs/and/opt/lampp/apache/logs/ - Files:
access.logerror.log- Any rotated log files (e.g.,
error.log.1,access.log.1,.gz, etc.)
- Why: These logs can get huge, fast.
- How:
- Delete old rotated/compressed logs (e.g.,
*.gz,.1files) - Truncate main logs regularly (to avoid interrupting Apache):
> /opt/lampp/logs/access.log > /opt/lampp/logs/error.log
- Delete old rotated/compressed logs (e.g.,
B. PHP Error Logs
- Location:
/opt/lampp/php/logs/ - Files:
php_error_log
- Why: Captures PHP warnings/errors, can grow large.
- How:
- Truncate periodically:
> /opt/lampp/php/logs/php_error_log
- Truncate periodically:
C. MySQL Log and Error Files
- Location:
/opt/lampp/var/mysql/or/opt/lampp/mysql/data/ - Files:
hostname.err(e.g.,ip-172-31-34-212.err)mysql-bin.*(binary logs, if enabled)- Slow query logs (
mysql-slow.log, if enabled) - Old rotated logs (
*.old,*.BAK, etc.)
- Why: Large logs waste space; old binlogs arenโt needed after backup/replication.
- How:
- Truncate the error log (never delete while MySQL is running):
> /opt/lampp/var/mysql/ip-172-31-34-212.err - Remove old binlogs (only if not needed for recovery/replication):
rm /opt/lampp/var/mysql/mysql-bin.00000*
ibdata1,ib_logfile*,aria_log*, or any database folders/files here. - Truncate the error log (never delete while MySQL is running):
D. Temporary Files
- Location:
/opt/lampp/temp/,/opt/lampp/tmp/, and projectstorage/framework/cache,storage/framework/sessions, etc. - Files:
- Upload temp files, session files, cache
- Why: Safe to delete files not recently accessed (stale session, cache, failed uploads).
- How:
- Example to remove files older than 2 days:
find /opt/lampp/temp/ -type f -mtime +2 -delete find /opt/lampp/tmp/ -type f -mtime +2 -delete
- Example to remove files older than 2 days:
E. Application/Framework Cache & Session Files
- Laravel example:
/opt/lampp/htdocs/your_project/storage/framework/sessions//opt/lampp/htdocs/your_project/storage/framework/cache//opt/lampp/htdocs/your_project/storage/framework/views/ - Why: Sessions, cache, and compiled views are safe to clear out if old.
- How:
find /opt/lampp/htdocs/your_project/storage/framework/sessions/ -type f -mtime +1 -delete find /opt/lampp/htdocs/your_project/storage/framework/cache/ -type f -mtime +1 -delete find /opt/lampp/htdocs/your_project/storage/framework/views/ -type f -mtime +1 -delete
F. Old Backup Files
- Location: Wherever you store old
.sql,.tar,.gz, etc. (often/backups/or/opt/lampp/htdocs/backups/) - Why: Donโt keep too many old backups.
- How:
find /opt/lampp/htdocs/backups/ -type f -mtime +7 -delete(Deletes backup files older than 7 days.)
4. What Should You NEVER Delete?
- Database data files (
ibdata1,ib_logfile0, etc. invar/mysql/) - Anything inside database directories (unless you want to drop/delete a database)
- Application files, user uploads, etc. (unless verified as junk)
- XAMPP config files
5. Automating Cleanup With a Cron Job
Hereโs a sample script you could run daily or weekly via cron:
#!/bin/bash
# Clean Apache logs (keep last 7 days)
find /opt/lampp/logs/ -type f -name "*.gz" -mtime +7 -delete
find /opt/lampp/apache/logs/ -type f -name "*.gz" -mtime +7 -delete
# Truncate current log files
> /opt/lampp/logs/access.log
> /opt/lampp/logs/error.log
> /opt/lampp/php/logs/php_error_log
# Truncate MySQL error log
> /opt/lampp/var/mysql/ip-172-31-34-212.err
# Clean temp files older than 2 days
find /opt/lampp/tmp/ -type f -mtime +2 -delete
find /opt/lampp/temp/ -type f -mtime +2 -delete
# Clean Laravel/Framework session & cache files older than 1 day
find /opt/lampp/htdocs/your_project/storage/framework/sessions/ -type f -mtime +1 -delete
find /opt/lampp/htdocs/your_project/storage/framework/cache/ -type f -mtime +1 -delete
find /opt/lampp/htdocs/your_project/storage/framework/views/ -type f -mtime +1 -delete
# Clean old backup files (older than 7 days)
find /opt/lampp/htdocs/backups/ -type f -mtime +7 -delete
Code language: PHP (php)
- Save this as
cleanup_xampp.sh - Make it executable:
chmod +x cleanup_xampp.sh - Add to crontab for daily execution (example at 2:30am):
30 2 * * * /path/to/cleanup_xampp.sh
6. Monitoring Disk Usage
- Regularly check usage:
du -sh /opt/lampp/* - Be proactive; if logs grow rapidly, increase cleanup frequency or log rotation.
7. Security and Best Practices
- Always review before deletingโautomate with care.
- Take regular full backups before aggressive cleaning, especially before touching anything in
var/mysql/. - Set up logrotate for Apache, PHP, and MySQL logs for better management.
- Document your cleanup routines for the team.
Summary Table
| Location | What to Clean | Command Example | Notes |
|---|---|---|---|
/opt/lampp/logs/ | Apache logs | > access.log | Rotate/truncate; donโt delete active logs |
/opt/lampp/php/logs/ | PHP logs | > php_error_log | |
/opt/lampp/var/mysql/ | MySQL error logs | > hostname.err | Never delete core DB files |
/opt/lampp/tmp/ /opt/lampp/temp/ | Temp files | find ... -mtime +2 -delete | Only old files |
/opt/lampp/htdocs/project/storage/ | Sessions, cache | find ... -mtime +1 -delete | Framework-specific |
/opt/lampp/htdocs/backups/ | Old backups | find ... -mtime +7 -delete | Optional |
Conclusion
Regular cleanup of log, temp, and cache files under /opt/lampp keeps your production XAMPP environment healthy, secure, and reliable.
Never delete database or config files, always backup before cleaning, and automate your routines for peace of mind!
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals
Very helpful guide! The explanation of which XAMPP/LAMPP files and logs should be cleaned in a production environment is clear and practical. Itโs a useful reference for developers and admins who want to keep their server organized and running smoothly.