summaryrefslogtreecommitdiffstats
path: root/INSTALL
blob: 03adc350b5169bcfa8dbd1d70d0e8c4668142047 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
$Id: INSTALL,v 1.8 2002/05/14 21:47:14 helios Exp $


Requirements
============

* I run a Red Hat 6.2 system, but these instructions should easily
  adapt to any modern distro.

* Apache 1.2 or 1.3 installed.  (I run 1.3.22 and it works fine). 
  You should have already successfully compiled Apache and know what
  you're doing there.  In fact, you should already have any other
  modules and add-ons like mod_ssl or PHP configured and installed
  before you start this process.

* The MySQL development headers.  (I run MySQL-devel-3.23.44-1.i386.rpm).  

* MySQL >= 3.23.15 configured, installed and running on either
  localhost or an accessible networked machine.  You should already
  have a basic understanding of MySQL and how it functions.

* Again, basic administrative skills with Apache and MySQL.  I try to
  make things as easy as possible in this README, but its purpose is
  not to be an administrative tutorial.

* Additionally, if you want to be able to log SSL information such as
  keysize or cipher, you need OpenSSL and glibc-devel installed.  Both
  are available as RPMs.


Do I want a DSO?
================
You need to know the answer to this question before you proceed.  The
answer is pretty straightforward:  what have you done in the past?  If
you like all your Apache modules to be dynamic, then you should keep
doing that.  If you're more of an old-school type and prefer to compile
the modules right into apache, do that.  Both methods work equally
well.


Installation (as an Apache DSO)
===============================

For folks interested in using this module as an Apache DSO:

0) Perform all the following steps as root so that you have install
   privs, etc.

1) Unpack the archive into a working directory.

   # tar zxf mod_log_sql.tar.gz -C /usr/local/src
   # cd /usr/local/src/mod_log_sql

2) Edit Makefile and make any adjustments for your system.  These are
   fully explained in the Makefile.

3) Instruct apxs to compile and install the module as a DSO.  You need
   to know two things before you run apxs:
   - The location of the apxs binary, find using 'locate apxs'
   - The location of your MySQL libraries, find using 'locate libmysqlclient'

   FORMAT:
   # <path>/apxs -i -c -L/path/to/mysqllibs -lmysqlclient -lz mod_log_sql.c

   EXAMPLE:
   # /usr/sbin/apxs -i -c -L/usr/lib/mysql -lmysqlclient -lz mod_log_sql.c

   You should see something like this:

	gcc -fpic -DSHARED_MODULE -I/usr/local/Apache/include -c mod_log_sql.c
	ld -Bshareable -o mod_log_sql.so mod_log_sql.o
	cp mod_log_sql.so <your path to Apache libexec>/mod_log_sql.so
	chmod 755 <your path to Apache libexec>/mod_log_sql.so
	[activating module blah in /path/to/apache/etc/httpd.conf]

4) Add the following stanzas to your httpd.conf file.  Put the second stanza
   somewhere after the ClearModuleList directive.

	<IfDefine HAVE_LOG_MYSQL>
	   LoadModule mysql_log_module modules/mod_log_sql.so
	</IfDefine>


	<IfDefine HAVE_LOG_MYSQL>
	   AddModule mod_log_sql.c
	</IfDefine>


5) Now go to step (9) in the instructions below to configure httpd.conf...


Installation (as a static module compiled into httpd)
=====================================================

[This is what I do, FYI.]

0) Perform all the following steps as root so that you have install
   privs, etc.

1) Unpack the archive into a working directory.

   # tar zxf mod_log_sql.tar.gz -C /usr/local/src
   # cd /usr/local/src/mod_log_sql

2) Examine the DEFINEs at the top of mod_log_sql.c and alter any that 
   you choose.  Edit Makefile and make any adjustments for your system.  
   These are fully explained in the Makefile.

3) # make all 
   (You should receive NO warnings or errors of any kind. 
   If you see messages like this: "mod_log_sql.c:69: httpd.h: No such
   file or directory" then you do not have your CFLAGS correctly
   pointing to the right include directory.)

4) # make install

5) Change to your Apache source dir.

   # cd /usr/local/src/apache-1.3.22/src

6) Re-make your httpd binary as follows.

   6a) Edit Configuration.apaci as follows...

       * Append the following string to the EXTRA_LIBS= line. (/usr/lib/mysql is where your libmysqlclient.a file lives):
       -L/usr/lib/mysql -lmysqlclient -lm -lz

       * Find the mod_log_config.o line, and add this line immediately after it:
	  AddModule modules/sql/mod_log_sql.o

   6b) # cp Configuration.apaci Configuration

   6c) # ./Configure

   6d) # make

   6e) # strip httpd

7) Test your new apache binary:

   # ./httpd -l

   You should see something like:

	Compiled-in modules:
	  http_core.c
	  mod_log_sql.c    <-- That's the line you're looking for.
	  mod_env.c
	  mod_log_config.c
	  mod_mime.c
	  mod_negotiation.c
       ...etc...

8) Install your httpd binary.  Copy it over your old httpd binary,
   wherever it lives.  You can and should rename your old httpd first so
   that you can easily revert to that working version in case of bugs or
   whatever.
 
   # /etc/rc.d/init.d/httpd stop
   # cp -f ./httpd /usr/local/Apache/bin/

9) Configure your apache daemon to log to your database.  Here's a very
   basic set of config lines to start you off.  Full documentation is
   available here: http://www.grubbybaby.com/mod_log_sql/directives.html

   EXAMPLE: Connect to the MySQL database called "apache" running
   on "dbmachine.foo.com".  The module uses username "loguser" and
   password "l0gger" to authenticate to the database; this user must,
   of course, exist in the MySQL user table and have the proper
   permissions -- more on that in step 11.  The log entries will be
   INSERTed into the table called "access_log".


   MySQLLoginInfo dbmachine.foo.com loguser l0gger
   MySQLDatabase apache

   <VirtualHost 1.2.3.4>
        [snip]

        MySQLTransferLogTable access_log
        MySQLTransferLogFormat huSUsbTvRA

        [snip]
   </VirtualHost>


   9a) Special step for users who have a DSO-enabled httpd:

	  If you you are building mod_log_sql as a static module BUT
	  your httpd is enabled for DSOs, add the following line to your
	  httpd.conf:

       AddModule mod_log_sql.c 


10) If you compiled mod_log_sql with the ability to make its own tables
    then you can skip this step.  Otherwise you need to do it by hand:

    Create a database and table to hold the new log data.  I log the
    same data as the regular "combined log" plus a little extra information
    that can be useful.

    The order that the fields appear in the table is irrelevant
    because you can SELECT them in any order you choose.  To create
    this table I first created a new database called "apache":

    # mysql -uadmin -pmypassword
    mysql> create database apache;

    Then create the table called "access_log".  I enclosed an SQL file
    that will create every column type that mod_log_sql supports. 
    Unless you're just testing or playing around, this is probably NOT
    what you want, so edit the file first and delete the lines that
    don't pertain to you.  Then:

    mysql> source access_log.sql


11) Create a specific MySQL userid that httpd will use to authenticate
    and enter data.  This userid need not be an actual Unix user.  It
    is a userid internal to MySQL with specific privileges.
	
	mysql> grant insert,create on apache.* to loguser@my.apachemachine.com identified by 'l0gger';
	
	Security is a very real concern.  mod_log_sql by default is 
	set up to create the SQL tables it needs.  If you have deactivated
	this capability, then create a user called "loguser" with the password
	"l0gger" with only the capability of INSERT to "access_log":

    mysql> grant insert on apache.access_log to loguser@my.apachemachine.com identified by 'l0gger';


12) Enable full logging of your MySQL daemon (at least temporarily
    for debugging purposes) if you don't do this already:

    Edit /etc/my.cnf and add the following line to your [mysqld] section:

      log=/var/log/mysql-messages

    Then restart MySQL.

13) Restart apache.

    # /etc/rc.d/init.d/httpd start

13) Load your web site in a browser to trigger some hits, then confirm that 
    the entries are being successfully logged:

    # mysql -hmysql.host.com -umysqladmin -p -e "select * from access_log" apache;
    Enter password:

    +---------------------------------------------------+-------------+-------------+------------------+------------------+------------+--------+------------+------------------------------------+
    | remote_host                                       | remote_user | request_uri | request_duration | virtual_host     | time_stamp | status | bytes_sent | referer                            |
    +---------------------------------------------------+-------------+-------------+------------------+------------------+------------+--------+------------+------------------------------------+
	[snipped lines]
	.
	.
	.
    +---------------------------------------------------+-------------+-------------+------------------+------------------+------------+--------+------------+------------------------------------+

14) You have basic functionality.  Don't disable your regular Apache logs until
    you feel comfortable that the database is behaving as you'd like and that
    things are going well.  




d>Gravatar Christopher Powell 2002-11-14 | * *** empty log message ***1.17pre2Gravatar Christopher Powell 2002-09-04 | * Lots of changes & bugfixes as requested on the list. Pre-1 of 1.17.1.17pre1Gravatar Christopher Powell 2002-06-27 | * More effort toward next release. Now include headers in/out.Gravatar Christopher Powell 2002-05-24 | * Further changes on the way to 1.17, big one was the segfault fix.Gravatar Christopher Powell 2002-05-16 | * Removed (TM)s.Gravatar Christopher Powell 2002-05-14 | * Added notes logging capability. This is a commit prior to a lot of workGravatar Christopher Powell 2002-05-14 | | | | | that will rename mod_log_mysql to mod_log_sql. * Moved the create_tables flag to the 'main server' and out of virtual-host1.16Gravatar Christopher Powell 2002-04-23 | | | | | space. * Significant headway toward a releasable 1.16, passed ab testing and myGravatar Christopher Powell 2002-04-23 | | | | | own hand tests. Mods documented in CHANGELOG. * Significant bugfixes and feature additions on the way to 1.16...Gravatar Christopher Powell 2002-04-21 | * Fixed buglet with preserve file (needed semicolon) and updated README.1.15Gravatar Christopher Powell 2002-04-08 | * *** empty log message ***Gravatar Christopher Powell 2002-04-08 | * Added - but did not activate - routines to handle proxy environment variables.Gravatar Christopher Powell 2002-04-08 | * This is a "pre" snapshot of 1.15. Numerous changes emphasizing how SQLGravatar Christopher Powell 2002-04-02 | | | | | | errors are reported and handled. Any missed queries during SQL downtime are written out to a textfile. * *** empty log message ***1.14Gravatar Christopher Powell 2002-02-24 | * Minor but significant updates to the instructions for apxs users.Gravatar Christopher Powell 2002-02-24 | * Ported to mysql_real_connect, made a change for the mass-virtual-hosting1.13Gravatar Christopher Powell 2002-01-15 | | | | | folks, and enabled a socket name DEFINE. * Fixed another typo in make_combined_log; improved DSO instructionsGravatar Christopher Powell 2002-01-02 | | | | | based on a user's input. * Added a mysql_close mechanism to the child exit process to fix MySQLGravatar Christopher Powell 2001-12-07 | | | | | | complaining about bad communication packets. Considerable code reorg and cleanup. * Fixed a bug where make_combined_log.pl's data[] types were off by one1.121.11Gravatar Christopher Powell 2001-12-04 | | | | | due to an earlier deletion from the SELECT statement. * 'make distro' now copies textfiles to html directory for online perusal.Gravatar Christopher Powell 2001-12-03 | * Big changes including reworked cookie code, new directives, SSL logging,Gravatar Christopher Powell 2001-12-03 | | | | | new formatting characters, bugfixes, etc. * A lot of code cleanup and tweaking, plus cookie logging:1.10Gravatar Christopher Powell 2001-11-30 | | | | | | | | | | | * New capability: log mod_usertrack cookies. * Some code cleanup and commenting. * Referer and User-Agent now set to want_orig=1 ( a very minor detail ) * Corrected mysql_escape_log to properly check for and escape strings with 'dangerous' characters. It appears that it was doing this incorrectly before. * Deleted log_mysql_child(), a function that was never called.