In this article I try to explain how to create our own log file in apache2. Log files are there to keep records about the details of users ,time , host's IP etc.. These details are used to analyzed about the users who visits web sites.
First of all you had to create a web site and should host in apache server.Following guidelines will help to you.According to your document root create a directories to keep your index file.
In my case I keep it /var/www/www.mypage.lk/htdocs. If you are not define custom log file to your site it will go to default place in /var/log/apache2 .And I create a log directory in side the www.mypage.lk to keep records of www.mypage.lk.
Normally log files are keep in /var/log/apache2. This is the default directory where apache log files are keep. In this scenario I create log directory inside the www.mypage.lk directory. So my log file path will be /var/www/www.mypage.lk/logs.
go to /etc/apache2 and edit ports.conf file ( you can use an editor like vi or nano)
and change Listen 8080 (any port you can use)
then go to the sites-available directory and create text file www.mypage.lk and It should be like this
use this command to edit $vi /etc/apache2/sites-available/www.mypage.lk . (You should first crate a file in sites-available directory)
------------www.mypage.lk--------------------
#
# Example.com (/etc/apache2/sites-available/www.mypage.lk)
#
NameVirtualHost 127.0.0.1:8080
<VirtualHost 127.0.0.1:8080>
ServerAdmin webmaster@localhost
ServerName www.mypage.lk
ServerAlias www.mypage.lk
# Indexes + Directory Root.
DirectoryIndex index.html
DocumentRoot /etc/www/www.mypage.lk/htdocs/
# CGI Directory
ScriptAlias /cgi-bin/ /var/opt/www.mypage.lk/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
# Logfiles
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" %T" timed-combined
LogFormat "%T \"%r\"" mylog
#ErrorLog /var/opt/www.mypage.lk/logs/error.log
CustomLog /var/opt/www.mypage.lk/logs/access.log mylog
</VirtualHost>
as I explain in previous article you should create a symlink $ a2ensite www.mypage.lk and keep record in /etc/hosts file as 127.0.0.1 www.mypage.lk .
Then when ever you type www.mypage.lk in browser it should shows your index file.
note : you can use any IP address and It should be a ip of apache server running.
In blue color shows what are the parameters should be recorded in log file. You can change it according to your preference. These are the some meanings of them.
This is the record that we can see in the access.log in www.mypage.lk relevant to Log Format of LogFormat "%T \"%r\"" mylog.
0 "GET / HTTP/1.1"
note : This is for apache2 in ubuntu and this may be change in other linux distributions.
First of all you had to create a web site and should host in apache server.Following guidelines will help to you.According to your document root create a directories to keep your index file.
In my case I keep it /var/www/www.mypage.lk/htdocs. If you are not define custom log file to your site it will go to default place in /var/log/apache2 .And I create a log directory in side the www.mypage.lk to keep records of www.mypage.lk.
Normally log files are keep in /var/log/apache2. This is the default directory where apache log files are keep. In this scenario I create log directory inside the www.mypage.lk directory. So my log file path will be /var/www/www.mypage.lk/logs.
go to /etc/apache2 and edit ports.conf file ( you can use an editor like vi or nano)
and change Listen 8080 (any port you can use)
then go to the sites-available directory and create text file www.mypage.lk and It should be like this
use this command to edit $vi /etc/apache2/sites-available/www.mypage.lk . (You should first crate a file in sites-available directory)
------------www.mypage.lk--------------------
#
# Example.com (/etc/apache2/sites-available/www.mypage.lk)
#
NameVirtualHost 127.0.0.1:8080
<VirtualHost 127.0.0.1:8080>
ServerAdmin webmaster@localhost
ServerName www.mypage.lk
ServerAlias www.mypage.lk
# Indexes + Directory Root.
DirectoryIndex index.html
DocumentRoot /etc/www/www.mypage.lk/htdocs/
# CGI Directory
ScriptAlias /cgi-bin/ /var/opt/www.mypage.lk/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
# Logfiles
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" %T" timed-combined
LogFormat "%T \"%r\"" mylog
#ErrorLog /var/opt/www.mypage.lk/logs/error.log
CustomLog /var/opt/www.mypage.lk/logs/access.log mylog
</VirtualHost>
as I explain in previous article you should create a symlink $ a2ensite www.mypage.lk and keep record in /etc/hosts file as 127.0.0.1 www.mypage.lk .
Then when ever you type www.mypage.lk in browser it should shows your index file.
note : you can use any IP address and It should be a ip of apache server running.
In blue color shows what are the parameters should be recorded in log file. You can change it according to your preference. These are the some meanings of them.
%h The remote host %l The remote logname (usually just "-") %u The authenticated user (if any) %t The time of the access \"%r\" The first line of the request %>s The final status of the request %b The size of the server's response, in bytes \"%{Referer}i\" The referrer URL, taken from the request's headers \"%{User-Agent}i\" The user agent, taken from the request's headers
In green color represent the name of each format of log. And you can create several formats by changing name. To assign each format you should give format name with relevant path to the log file. In red color represent the file path to our log file. Access.log is the log file name.
This is the record that we can see in the access.log in www.mypage.lk relevant to Log Format of LogFormat "%T \"%r\"" mylog.
0 "GET / HTTP/1.1"
note : This is for apache2 in ubuntu and this may be change in other linux distributions.
Keep it up. We are really following you !!!
ReplyDelete