Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours scrolling social media and waste money on things we forget, but won’t spend 30 minutes a day earning certifications that can change our lives.
Master in DevOps, SRE, DevSecOps & MLOps by DevOpsSchool!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

XAMPP – LAMPP Tutorials: List of Production Files to Cleanup Guide

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.log
    • error.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, .1 files)
    • Truncate main logs regularly (to avoid interrupting Apache): > /opt/lampp/logs/access.log > /opt/lampp/logs/error.log

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

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*
    NEVER delete ibdata1, ib_logfile*, aria_log*, or any database folders/files here.

D. Temporary Files

  • Location: /opt/lampp/temp/, /opt/lampp/tmp/, and project storage/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

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. in var/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

LocationWhat to CleanCommand ExampleNotes
/opt/lampp/logs/Apache logs> access.logRotate/truncate; don’t delete active logs
/opt/lampp/php/logs/PHP logs> php_error_log
/opt/lampp/var/mysql/MySQL error logs> hostname.errNever delete core DB files
/opt/lampp/tmp/ /opt/lampp/temp/Temp filesfind ... -mtime +2 -deleteOnly old files
/opt/lampp/htdocs/project/storage/Sessions, cachefind ... -mtime +1 -deleteFramework-specific
/opt/lampp/htdocs/backups/Old backupsfind ... -mtime +7 -deleteOptional

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!


Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x