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:
-
Change the location of the error log file.
-
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: