I'm running a web server that uses PHP5 and SQlite for database queries. I have my crontab set to reboot the machine at midnight each day.

Every few days, all of my files in the /var/www folder are gone along with the folder itself. Apache2 gives me a 404 error. When I restart Apache2, it fails because the /var/log/apache2 folder is deleted.

How can I stop this?

  • Is there anything in your system logs? Try leaving a terminal running with the command "tail -f /var/logs/syslog" , and observe what shows up in the log when this happens. My guess is you have a mis-configured log rotation or something similar which is operating on your web-server route, one of the many log files in /var/logs should tell what was running and at what time, without knowing what was running when this happened, you have zero chance of figuring out what you need to stop. – shawty Apr 23 '17 at 12:51
  • I get the following error: tail: cannot open '/var/logs/syslog' for reading: No such file or directory – Elliot A. Apr 23 '17 at 12:54
  • @shawty That should have been /var/log/..., not /var/logs. I'm not sure how much help it will really be, but it is something you should get comfortable sifting through anyway so Elliot might as well start now. On Raspbian 8 (jessie) there is also the similar journalctl -x (see man journalctl). – goldilocks Apr 23 '17 at 14:05
  • 1
    For diagnosis, adding to what shawty said, you could write yourself a script that checks the existence of /var/www every minute and writes a message to your own log when it no longer exists. That way you would at least know when it happens (time stamp on file). I'm not expert enough to sit here and quote the code but I googled this quickly: if [ ! -d "$DIRECTORY" ]; then # Control will enter here if $DIRECTORY doesn't exist. fi Also, maybe a permissions/owner change to stop it being deleted but I wouldn't change anything until I figure out what's going on. – MartinMarty Apr 23 '17 at 19:55
  • 1
    Another angle: Is your web server reachable from the public Internet? Does any part of your PHP code delete files? Can a web crawler delete files simply by following all of the hyperlinks on your website? (This has happened to people before.) – Hydraxan14 Apr 24 '17 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.