0

The apache2 service on debian 12 doesn't seem to work for me.
It complains in the logs something about /var/log/apache2.
The apache2 subdirectory doesn't seem to exist in the /var/log directory.

The temporary fix I have is to do sudo mkdir /var/log/apache2 and restart the apache service. But after I do a system restart, the apache2 subdirectory does not stay at /var/log hence I need to run mkdir again to create the apache2 subdirectory again.

Making this /var/log/apache2 directory fixes this issue I am facing. I would like a more permanent way to resolve this issue rather than create the apache2 directory in /var/log.

The systemctl start apache2 was run with sudo privileges but it doesn't seem to impact anything and complains that /var/log/apache2 doesn't exist and cannot generate log hence the service doesn't run at all until the specified directory is made.

0

2 Answers 2

1

I think i figured out what was causing it. It was Stacer deleting the apps log files hence on reboot the service won't Start because of the missing directory. Which is why I initially though it was something with rebooting. Thanks for the help.

1
  • For sure, glad you were able to get it sorted out Commented Dec 31, 2023 at 13:58
0

Nothing should be deleting your /var/log/apache2/ directory and if it is, you need to do this and find out what's deleting it and report it:

mkdir -p /var/log/apache2
chown root:adm /var/log/apache2
chmod 750 /var/log/apache2
touch /var/log/apache2/.write-protect
chattr +i /var/log/apache2/.write-protect

this will prevent the directory from being recursively or forcefully deleted, and any attempt will result in: rm: cannot remove 'apache2/.write-protect': Operation not permitted because the .write-protect file has been made immutable and can't be deleted. Note: this will not prevent other files in the directory from being deleted, but rather just the .write-protect file itself and subsequently prevent the parent directory because directories can't be deleted unless they're empty. I really can't imagine what could possibly be deleting your logs directory, though and whatever it is needs to be corrected.

The only other explanation I can think of is that your /var/log or /var/log/apache2 directory is being mounted from tmpfs (as unlikely as it seems its not unimaginable but it would certainly be custom) in which case everything will always be ephemeral and you will need to modify your apache2 service unit to make sure the directory is created, you could do that like:

systemctl stop apache2
systemctl disable apache2
cp /usr/lib/systemd/system/apache2.service /etc/systemd/system/my-apache2.service
  • edit the /etc/systemd/system/my-apache2.service and add the following line under [Service]:

ExecStartPre=mkdir /var/log/apache2 && chown -R root:adm /var/log/apache2 && chmod 750 /var/log/apache2

save the contents then exit, and type systemctl daemon-reload and type systemctl start my-apache2 and check that it starts OK with systemctl status my-apache2 if it does, systemctl enable my-apache2 to have it start at boot each time.

1
  • If the breaking change of preventing that directory from being deleted doesn't help you isolate what's actually deleting it you may want to consider something like inotifywait to try to track down and root cause that: apt install inotify-tools and man inotifywait Commented Dec 27, 2023 at 18:15

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.