updates
[mir.git] / doc / INSTALL.mir
1 MIR INSTALLATION HOWTO
2
3 Last updated: $Date: 2002/07/03 12:07:58 $
4 ----------------------------------------------------------------
5
6 Here is a short installation-howto of Mir.
7
8
9 prerequisites: 
10
11 - tomcat 4.0.3 or above (3.3 works too as of 04.04.2002, but this could change)
12   tomcat is available from http://jakarta.apache.org/tomcat/
13 - apache with mod_jk.so http://httpd.apache.org
14 - postgres 7.1.x or 7.2.x. http://www.postgresql.org
15 - ant (a java-based make) 
16 - jaxp-1.1 (a SAX 2.0 compliant XML parser, comes with ant >= 1.4)
17 - the JAI image framework (Java Advanced Imaging) versin 1.1.1 . get it from 
18   java.sun.com. ** NOTE: because JAI uses a native acceration library (a .so)
19   it must be placed in tomcat's "lib" (i.e $TOMCAT_HOME/lib) directory and
20   not under the default webapps/Mir/WEB-INF/lib directory **
21 - A good reading of Tomcat, Apache and Postgresql documentation if you are not
22   familiar with any of them. The documentation is available at:
23   http://jakarta.apache.org/tomcat/tomcat-4.0-doc/index.html,
24   http://httpd.apache.org/docs/ and http://www.postgresql.org respectively.
25
26 1. checkout the cvs
27
28 CVS LOGIN:
29
30   cvs -d :pserver:anonymous@mir.indymedia.org:/var/lib/cvs login
31         password: anonymous
32
33 CVS CHECKOUT:
34
35         cvs -d :pserver:anonymous@mir.indymedia.org:/var/lib/cvs co mir 
36
37
38 2. customize the config: 
39
40         cd mir/source 
41         cp config.properties-dist config.properties 
42
43 now customize config.properties for your needs.
44
45
46 3. configure the perms.sh file if neccessary -- IMPORTANT! READ THIS!
47 We provide a script that sets all files' and direcories' permissions to
48 a quite reasonable state. This script gets automagically called by
49 ant after compilationl. The most important thing you have to do after
50 compiling Mir is to ensure that the log files -- especially 
51 dbentity.log -- are not readable by users that could compromise 
52 system security, because all passwords and the like will be logged here.
53         
54         cp perms.sh-dist perms.sh
55
56 Now, change the install directory and group in perms.sh
57
58         edit perms.sh 
59
60
61 4. copy the mir/templates-dist-directory to mir/templates
62
63
64 5. compile. For this step, you have to make sure that the TOMCAT_HOME
65 environment variable is set to the root of your tomcat installation.
66 The build.xml compile target will give up if this is not set.
67
68 Do this as root so the permissions script is able to set
69 the permissions and owners correctly.
70
71     ant 
72
73
74 6. Link in the webapps directory of tomcat to the install directory (the 
75 directory is called "Mir" and is located in the same directory in which 
76 you installed the "mir" directory). (Here and in the rest of this document,
77 we assume you called the link "Mir", but this could be named anything.)
78         cd /path/to/tomcat/webapps (tomcat-4.0.x/webapps)
79         ln -s /path/to/Mir Mir
80
81 with tomcat 4.0.x, you could dynamically reload and stop the Mir webapp without
82 restarting tomcat by using the "Manager App" with the following url:
83
84 http://localhost:8080/manager/stop?path=/Mir
85
86 This is practical if you are running several installations of mir on one 
87 tomcat or other webapps and can't afford to shutdown all of them.
88 See the tomcat documentation to learn how to enable and use the manager app.
89
90 7. Copy any dynamic library files ending with ".so" (so far only the JAI native
91 acceleration library found in the JAI package tarball or zip from sun) to your
92 $JAVA_HOME/jre/lib/i386 directory (where the other ".so" files live). Or, you
93 can skip the whole thing and live without "native" acceleration for image
94 manupulation.
95
96 8a. create a new database 
97 The database name should be the same as in config.properties. Please look at
98 the section "Database.*" to look up the names or change them to your needs. 
99
100 It is wise in terms of system seurity to use an unprivileged user for this
101 task instead of the superuser. This is because if Mir uses the superuser to
102 connect to the database and anybody manages to find out the password Mir 
103 uses to connect, the attacker can take over the complete database. So, in
104 the following examples, we assume that the database name is "Mir", the
105 database user will be "mir" and the password is "joshua". Please note that
106 this particular password is far from being a good one. Watch "Wargames" for
107 details. =B) 
108
109 To access the database as the database superuser, you either have to log in
110 as postgres on Unix level (which we don't recommend because you will need
111 another user to have a login shell and a password which makes system
112 penetration more likely) or you have to tell PostgreSQL with each
113 application call that you want to connect as a specific user. If you access
114 the database from any other user's account, use the -U flag to connect to
115 PostgreSQL as the database superuser ("postgres"):
116
117         createdb -U postgres --encoding=unicode Mir 
118
119 Please note that if you create the database from inside the psql application,
120 the database name will likely be converted to lowercase letters.
121
122
123 8b. create an unprivileged database user for Mir
124 First, connect to the database as the database's superuser. 
125
126         psql -U postgres Mir
127
128 Now we create the actual user. Please choose a password that is hard to 
129 guess instead of "joshua". Good passwords have characters and numerals in
130 it, have no link to its owner (like being her birthday, age, name of her 
131 husband, dog, child, car, favourite beer brand). A good password looks like
132 this: "8ncx4un".
133     
134     CREATE USER Mir WITH PASSWORD 'joshua' NOCREATEDB NOCREATEUSER;
135
136 8c. create base table
137 Please note that we use the superuser "postgres" to connect to the "Mir"
138 database, /not/ the user "mir". 
139
140         psql -Upostgres -f dbscripts/create_pg.sql Mir
141     for i in dbscripts/help*.sql ; do psql -Upostgres -f $i Mir ; done
142     for i in dbscripts/populate*.sql ; do psql -Upostgres -f $i Mir ; done
143
144 8d. Grant the required permissions to the new user
145
146 -- The following should be executed as the "postgres" DB user.
147 -- Note that ID_FROM_PG_USER and DATABASENAME should be replace with the 
148    appropriate field values from the 2 prior selects.
149 -- set owner of datbase
150 select * from pg_database;
151 select * from pg_user;
152 update pg_database set datdba=ID_FROM_PG_USER where datname=DATABASENAME
153
154 -- find all tables to grant privs / select is just building sql
155 -- to be exectued
156
157 select 'grant all on '||relname||' to "de_indy";'
158 from pg_class
159 where relname not like 'pg%'
160 order by relname;
161
162 8e. Apply neccessary changes to config.properties
163
164 Please open config.properties and look for the lines that begin with
165 "Database.". The interesting properties are "Username", "Password", "Host"
166 and "Name". Change these properties so that they reflect the settings you
167 used to create the database and the user.
168
169 You should make sure that no copy of config.properties (neither in mir nor
170 in Mir/src nor in Mir/WEB-INF/classes nor in the directory tree you compiled
171 Mir from) is world-readable. Else you wouldn't have to install a password,
172 anyway.
173
174 8f. Setup PostgreSQL so that all connections have to pass a password
175
176 In /etc/postgresql/pg_hba.conf you should make sure that nobody can
177 use the database without a password:
178
179 local            all                                                                               password
180 host         all         127.0.0.1     255.0.0.0           password
181 host         all         0.0.0.0       0.0.0.0             reject
182
183 This means: All local connections (i.e. psql without "-h hostname" option)
184 have to authenticate themselves with a password. All connections from
185 localhost (127.0.0.1) have to supply a password, too. All other connections
186 are rejected. This line doen't have to be there if you have a properly
187 configured firewall but even if you do have one, it adds to the security in
188 case an attacker penetrates the firewall by some hack.
189
190 If you can't access PostgreSQL after this for any reason, try and change
191 "password" in /etc/postgresql/pg_hba.conf to "trust". This should disable
192 any authentication method and make the database accessible again. Please use 
193 this setting only temporarily because anybody who can access the PostgreSQL
194 server could take over the database completely this way. After you fixed
195 your password setting, switch the setting back to "password".
196 You may want to change your PostgreSQL password from time to time to make
197 database takeover harder. Rememer: Security is a process.
198
199
200
201 9. Add the dupe prevention trigger to the database:
202         cd dbscripts/dupetrigger
203         
204         There, read INSTALL and follow the instructions.
205         
206
207 10. Tweak mime-type extensions mappings in etc/web.xml file.
208
209 *** Note the defaults should be o.k for most installations ***
210
211 Add or remove any mime types you wish to support. This is used to figure
212 out the mime-type when (broken browsers?) browsers don't send the mime-type
213 in the content-type header field when uploading a media file. Note add the
214 moment you still have to add these to the media_type SQL table as well which
215 maps the mime-types to the correct mediaHandler class. See the comments in
216 the MirMedia class in javadoc for more details.
217
218 11. restart tomcat 
219
220 12. configure mod_jk 
221
222 There are 2 ways to do this. auto-generation of mod_jk.conf or manula JKMount
223 lines. (rumour has it that Tomcat 4.0.x doesn't support auto-generation, but
224 this is unconfirmed).
225
226 In both examples please note that the JkWorkersFile line only needs to appear
227 once per Apache config.
228
229 Also this assumes that your tomcat installation has it's ajp13 conenctor 
230 turned on. See tomcat's server.xml file and documentation for this. Chances
231 are that it is turned on.
232
233 Method a). The automatic mod_jk.conf method:
234
235 insert the following patch into /etc/apache/httpd.conf. Edit the directories
236 to suit your needs.
237
238 <IfModule mod_jk.c>
239 JkWorkersFile /path/to/tomcat/conf/workers.properties
240 Include /path/to/tomcat/conf/mod_jk.conf-auto
241 </IfModule>
242
243 Do not put any JkMount lines into your httpd.conf!
244
245 If mod_jk.conf-auto doesn't get written or is 0 bytes in size, check your
246 system for file ownership/permissions problems.
247
248 Method b). Manual JKMount lines
249
250 insert the following patch into /etc/apache/httpd.conf. Edit the directories
251 to suit your needs.
252
253 <IfModule mod_jk.c>
254 JkWorkersFile /path/to/tomcat/conf/workers.properties
255 JkMount /Mir ajp13
256 JkMount /Mir/* ajp13
257 </IfModule>
258
259
260 13. configure apache
261
262 edit http.conf:
263 * set the document root to the same directory as in the mir config file
264 * enable shtml includes:
265   - add LoadModule includes_module /usr/lib/apache/1.3/mod_include.so
266   - make sure your directory contains "Options Includes"
267 * Determine if you need to modify any apache mime-mappings
268   - The web-server host must recognize the .m3u, .pls and other file extensions
269     and send the proper "audio/x-mpegurl" and "audio/x-scpls" mime-types
270     respectively.  If the web server is apache, it's easy, just
271     add:
272     
273     audio/x-mpegurl                 m3u
274     audio/x-scpl                    pls
275     
276     to the file pointed to by the "TypesConfig" command in your apache config
277     file. Or add and equivalent AddType command to your httpd.conf.  Of course
278     this assumes that the mod_mime is loaded.
279
280 that's it :)
281
282 now the admin-application is accesable via:  
283
284         http://host/Mir/servlet/Mir 
285
286 and the openposting-servlet via  
287         
288         http://host/Mir/servlet/OpenMir
289
290 standard login is admin/indymedia. See the webdb_users SQL table to change/add
291 users or passwords.
292
293
294 SEARCHING
295
296 The Mir code offers no internal search facilities, rather, the design
297 expects the use of an external program to crawl and index the static
298 site.  One (recommended) tool for doing this is htdig
299 (http://htdig.org), which generates static databases of the site
300 content and then accesses those databases through a very fast CGI
301 program written in C.  In the scripts directory, a perl CGI script 
302 which wraps calls to htsearch is provided (scripts/search.pl) which
303 will allow searching based off of media type.  (This is possible
304 because the standard templates will include META keywords like
305 hasAudio, hasVideo, etc.)  
306
307 UPGRADING
308
309 see the UPGRADING.mir file.
310
311 TROUBLESHOOTING
312
313 You can give these a try if anything goes wrong:
314
315 + Restart Tomcat. Especially after compiling the sources Tomcat has to be
316   restarted.
317
318 + Check file permissions and ownership. Try and run perms.sh.
319
320 ----------------------------------------------------------------
321
322 $Date: 2002/07/03 12:07:58 $ - the Mir coders