Sometimes you may need to change log directory location for Apache web server. This may happen if you have limited disk space and your Apache log files exceed that limit. In this article, we will look at how to change Apache log location.
Where is Apache Log Located
In Redhat/CentOS/Fedora, Apache log files are typically located at /etc/httpd and it has symlinks from /etc/httpd/logs to /var/log/httpd. In Ubuntu/Debian systems, it is located at /var/log/apache2. You can use the following commands to find the location of your server log directory.
# grep CustomLog /usr/local/etc/apache22/httpd.conf # grep CustomLog /etc/apache2/apache2.conf # grep CustomLog /etc/httpd/conf/httpd.conf
How To Change Apache Log Location
We will look at two ways to change Apache log location.
1. Change symlink to update log location
You can simply move /var/log/httpd and update the symlinks. For example, let’s say you want to move your log folder to /home/ubuntu. Open terminal and run the following commands to first move the content in /var/log/httpd and update the symlink to it
$ sudo mv /var/log/httpd /home/ubuntu/httpd $ sudo ln -s /etc/httpd/logs /home/ubuntu/httpd
Also read : What File Permissions for Apache Files/Folders
2. Update Apache Configuration
If you have access to Apache’s configuration file, then open it (or virtual host configuration file) in a text editor.
$ sudo vi /etc/apache2/httpd.conf OR $ sudo vi /etc/apache2/sites-available/default-000.conf
Let us say you want to move your Apache logs to /home/ubuntu/httpd. Look for CustomLog and ErrorLog directives in the server/virtual host configuration file. Update them to the following
CustomLog /home/ubuntu/httpd ErrorLog /home/ubuntu/httpd
If you cannot find the above directives add them afresh. Please make sure to add absolute paths for these directives and not relative paths.
Restart Apache server to apply changes.
$ sudo service apache2 restart
That’s it. Now Apache server will automatically start writing to the log files in your new location.
Among the above two methods, the first is preferable because it doesn’t require you to access configuration file or restart your web server.
Also read : How to Disable TLS 1.0/1.1 in Apache Server