Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache2 create log as root and not as Apache user

Tags:

apache

I dont understand why apache2 create log as root and not as Apache user. This cause the problem that every day i need to restart the service.

This is my envvars configuration for the user:

export APACHE_RUN_USER=myuser
export APACHE_RUN_GROUP=myuser

And in apache2.conf i have the standard configuration for the user:

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

When i run/restart apache i use the command as root:

sudo service apache2 restart

If you need other information, i can tell you.

EDIT logrotate configuration for apache:

/var/log/apache2/*.log {
    daily
    missingok
    rotate 14
    compress
    delaycompress
    notifempty
    create 640 root adm
    sharedscripts
    postrotate
                if invoke-rc.d apache2 status > /dev/null 2>&1; then \
                    invoke-rc.d apache2 reload > /dev/null 2>&1; \
                fi;
    endscript
    prerotate
        if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
            run-parts /etc/logrotate.d/httpd-prerotate; \
        fi; \
    endscript
}

This is all the files presents in logrotate.d:

alternatives  apache2 apport  apt  certbot  dpkg  fail2ban  lxd  mysql-server  nginx  rsyslog  ufw  unattended-upgrades
like image 402
Mistre83 Avatar asked Jun 29 '26 06:06

Mistre83


1 Answers

The issue here most likely is that you changed the user account the apache http server is operated under without adjusting the configuration of the logrotation accordingly:

create 640 root adm

So the logrotate utility will create new log files with file system permissions your http server process will then not be able to open and write to...

like image 97
arkascha Avatar answered Jul 03 '26 10:07

arkascha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!