Technology3 min read

How to change Log file Location for Apache Webserver?

Abhishek Ahlawat

By Abhishek Ahlawat โ€” Recently

Founder of StudyTonight and a MERN fullstack developer. Writes about JavaScript, web development, Linux, and tech.

Summarize this article using AI

If you use the Apache webserver to host your website, and you are generally involved in the DevOps of the sever, then you might have to access the log files for your Apache web server very frequently. The Apache webserver files are stored in the apache2 directory on the server machine here: var/log/apache2/error.log but this can differ if you are using a different software setup for the LAMP stack, like Cpanel or Bitnami.

Now accessing the default location for logs of your server is not always easy and it can become cumbersome to jump so many directories to explore the log files.

Hence, we have 2 solutions to this problem:

  1. Change the location of the error log file.

  2. Create a soft link to the main log file for your apache server.

Change the Logfile Location for Apache:

We can do this by updating the configuration of the Apache webserver, using the ErrorLog configuration to provide the new location for the log files.

Here is the configuration line that you can use:

ErrorLog "C:\Users\.....\Desktop\log.txt"

The configuration file looks like this when you add the above line to it:

<VirtualHost *:80>
    RewriteEngine On
    # change location of log file
    ErrorLog "C:\Users\.....\Desktop\log.txt"
    ServerName .....
    DocumentRoot ....
    <Directory  ....>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

After changing the configuration, you should restart the Apache webserver.

The path can be any location that is accessible to the Linux user using which Apache webserver was started.

Create a soft link to the main log file:

We can also create a soft link for the default web server log file, to any file of our choice. A Soft link means that we can access the content of the main file using the soft link file.

Now, this is a nice way to access a file easily without changing its location permanently. If you want the log file to be stored in /home/studytonight/apache.log file, while the original log file is stored at location /var/log/apache2/error.log, then you can use the following command in Linux to create a soft link.

ln -s /var/log/apache2/error.log /home/studytonight/apache.log

This will create a soft link in the new location, using which you can access the logs.

Conclusion:

When you are a Server admin, you have to make these changes to make your life easier. Now this change may look very trivial, but when you have to access a file multiple times a day, such small tricks can make your life very easy.

You may also like:


Spotted something outdated or wrong?

Liked this? See more StudyTonight posts in Google results.

Add StudyTonight as a preferred source
Next questLIVE OPSStep 2 / 3

Practice real incidents in the browser

System Design Ops โ€” put out fires, ship fixes, and stack XP. Reading done. Time to play.

Play System Design
  • +XP

    Every sim

  • Incidents

    Live ops

  • Ranks

    Climb up

Read next