Linux – Changing Apache 2.4.x’s Log Files Directory on Centos 7

apache-2.4centos7linuxlogging

Currently my log files are avaliable under `/var/log/httpd/. Since I have limited amount of my root partition, the logs are exceeding the limit and causing system to stuck.

I want to change apache logging directory to another mounted volume.

I haven't changed & found anything about log file directory in config file, what would be the easiest way to change the /var/log/http/* directory to /someRandomVolume/httpLogFolder/*

This is what I have about log on my config file;

#
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog "logs/error_log"

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

<IfModule log_config_module>
    #
    # The following directives define some format nicknames for use with
    # a CustomLog directive (see below).
    #
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    #
    # The location and format of the access logfile (Common Logfile Format).
    # If you do not define any access logfiles within a <VirtualHost>
    # container, they will be logged here.  Contrariwise, if you *do*
    # define per-<VirtualHost> access logfiles, transactions will be
    # logged therein and *not* in this file.
    #
    #CustomLog "logs/access_log" common

    #
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    CustomLog "logs/access_log" combined
</IfModule>

Best Answer

On RHEL/CentOS the default location for log files is relative from the ServerRoot base directory /etc/httpd/ and typically a symlink from /etc/httpd/logs to /var/log/httpd.

If you want to use a different directory, simply move /var/log/httpd and update that symlink.

Alternatively, as @TomTomTom suggested, use absolute paths in the CustomLog and ErrorLog directives.

If you have SELinux enabled please ensure that the correct context is set/kept for that new directory.

Related Topic