Project

General

Profile

MAUSDjangoApache » History » Version 21

Jackson, Mike, 06 March 2012 14:51

1 18 Jackson, Mike
h1. Deploying the MAUS web-front end
2 1 Jackson, Mike
3
{{>toc}}
4
5 21 Jackson, Mike
This page describes how to deploy and run the MAUS web front-end. 
6
7
* The web front-end can either be run in the Django lightweight web server or under Apache 2.0. The latter is recommended for production environments.
8
* The MAUS software is not required to use the MAUS web front-end. However, if you do not have MAUS then you will need to install Python 2.7 and related packages.
9
10 14 Jackson, Mike
h2. Deploy Python 2.7 and related packages
11
12 16 Jackson, Mike
If you do *not* have and do *not* want to download the MAUS software (which comes with Python 2.7 and Python easy_install) then keep reading. 
13 1 Jackson, Mike
14 18 Jackson, Mike
Otherwise, *go down to* the next section, "Deploy ImageMagick".
15 16 Jackson, Mike
16 1 Jackson, Mike
For full information on deploying Python 2.7, see http://www.python.org/getit/releases/2.7/
17 14 Jackson, Mike
18 16 Jackson, Mike
To install Python 2.7.2 via building from it's source code:
19 14 Jackson, Mike
20
* Log in as super-user e.g. using @sudo su -@ or @su@.
21
* Get Python 2.7 source distribution and unpack it,
22
<pre>
23
$ wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
24
$ mv Python-2.7.2.tgz Python-2.7.2.tar.gz
25
$ gunzip Python-2.7.2.tar.gz 
26
$ tar -xf Python-2.7.2.tar 
27
$ cd Python-2.7.2
28
</pre>
29
* Configure,
30
<pre>
31
$ ./configure
32
</pre>
33
* Build,
34
<pre>
35
$ make
36
</pre>
37 15 Jackson, Mike
* Install,
38 14 Jackson, Mike
<pre>
39 1 Jackson, Mike
$ make install
40
</pre>
41 14 Jackson, Mike
42 16 Jackson, Mike
h3. Deploy Python setuptools
43 14 Jackson, Mike
44 16 Jackson, Mike
Now, install the Python setup tools (0.6c11) for Python 2.7. For full information, see http://pypi.python.org/pypi/setuptools.
45 14 Jackson, Mike
46
* Log in as super-user e.g. using @sudo su -@ or @su@.
47 16 Jackson, Mike
* Get the setuptools egg,
48 14 Jackson, Mike
<pre>
49
$ wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg#md5=fe1f997bc722265116870bc7919059ea
50
</pre>
51
* Execute the egg,
52
<pre>
53
$ sh setuptools-0.6c11-py2.7.egg 
54 1 Jackson, Mike
</pre>
55
56
This will install the Python @easy_install@ tool.
57
58
h2. Deploy ImageMagick
59
60 16 Jackson, Mike
The ImageMagick library is used to convert between image types in the MAUS web-front end. For full information see http://www.imagemagick.org/script/index.php
61 1 Jackson, Mike
62 16 Jackson, Mike
Check to see if you already have this as it is a commonly deployed tool,
63
<pre>
64
$ /usr/local/bin/convert -h
65
Version: ImageMagick 6.7.4-0 2011-12-13 Q16 http://www.imagemagick.org
66
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
67
Features: OpenMP    
68
</pre>
69
If so then *go down to* the next section on installing Django, MagickWand and PIL.
70 14 Jackson, Mike
71 16 Jackson, Mike
To install ImageMagick 6.7.4,
72
73 14 Jackson, Mike
* Log in as super-user e.g. using @sudo su -@ or @su@.
74
* Get and unpack ImageMagick,
75
<pre>
76
$ wget http://www.imagemagick.org/download/ImageMagick.tar.gz
77
$ gunzip ImageMagick.tar.gz
78
$ tar -xf ImageMagick.tar
79
$ cd ImageMagick-6.7.4-0/
80
</pre>
81
* Configure,
82
<pre>
83
$ ./configure
84
</pre>
85
* Make,
86
<pre>
87
$ make
88
</pre>
89
* Install,
90
<pre>
91
$ make install
92
</pre>
93
** This places libraries in @/usr/local/lib@.
94
* Cache the libraries,
95
<pre>
96
$ ldconfig /usr/local/lib
97
</pre>
98
** This avoids problems with libraries not being found by Python's magickwand library.
99 1 Jackson, Mike
* Check,
100
<pre>
101
$ /usr/local/bin/convert -h
102
Version: ImageMagick 6.7.4-0 2011-12-13 Q16 http://www.imagemagick.org
103
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
104 14 Jackson, Mike
Features: OpenMP    
105
</pre>
106
107 16 Jackson, Mike
h2. Deploy Django, MagickWand and Pyton Image Library Python packages
108 14 Jackson, Mike
109 16 Jackson, Mike
Install these Python packages using @easy_install@:
110
111
* If you do NOT have and do NOT want to download the MAUS software and have deployed Python 2.7 as a super-user then, first log in as super-user e.g. using @sudo su -@ or @su@.
112
* Run,
113 14 Jackson, Mike
<pre>
114
$ easy_install django
115
$ easy_install magickwand
116
$ easy_install pil
117
</pre>
118
119 16 Jackson, Mike
Check MagickWand,
120 14 Jackson, Mike
<pre>
121
$ python
122
$ import magickwand
123
$ from magickwand.image import Image
124
...
125
</pre>
126
* If you get an error like,
127
<pre>
128 1 Jackson, Mike
Traceback (most recent call last):
129
  File "<stdin>", line 1, in <module>
130
  File "build/bdist.linux-i686/egg/magickwand/image.py", line 2, in <module>
131 14 Jackson, Mike
  File "build/bdist.linux-i686/egg/magickwand/api/__init__.py", line 1, in <module>
132
    #
133
  File "build/bdist.linux-i686/egg/magickwand/api/lib.py", line 11, in <module>
134 20 Jackson, Mike
  File "/home/user/maus/third_party/install/lib/python2.7/ctypes/__init__.py", 
135 14 Jackson, Mike
  line 353, in __init__ self._handle = _dlopen(self._name, mode)
136
OSError: libMagickWand.so.5: cannot open shared object file: 
137
 No such file or directory
138
</pre>
139 16 Jackson, Mike
* then run @ldconfig@ as described in the instructions for ImageMagick above.
140
141 17 Jackson, Mike
h2. Deploy Apache 2.2
142 16 Jackson, Mike
143 1 Jackson, Mike
Apache 2.2 (http://httpd.apache.org/) is an HTTP server. For full deployment information, see http://httpd.apache.org/docs/current/install.html
144
145 19 Jackson, Mike
If you do *not* want to use Apache 2 but are happy to use the stand-alone lightweight Django web server then *go down to* Deploy the MAUS Django web front-end.
146 18 Jackson, Mike
147 17 Jackson, Mike
* Log in as super-user e.g. using @sudo su -@ or @su@.
148 1 Jackson, Mike
* Download,
149
<pre>
150
$ wget http://mirrors.ukfast.co.uk/sites/ftp.apache.org//httpd/httpd-2.2.22.tar.gz
151
</pre>
152
* Extract,
153
<pre>
154
$ gzip -d httpd-2.2.22.tar.gz 
155
$ tar xvf httpd-2.2.22.tar
156
$ cd httpd-2.2.22
157
</pre>
158
* Configure,
159
<pre>
160
$ ./configure
161
</pre>
162
** This uses a default deployment directory of @/usr/local/apache2@.
163
* Compile,
164
<pre>
165
$ make 
166
</pre>
167
* Install,
168
<pre>
169
$ make install 
170
</pre>
171
* Start-up server,
172
<pre>
173
$ /usr/local/apache2/bin/apachectl -k start
174
</pre>
175
** If you get an error like,
176
<pre>
177
(98)Address already in use: make_sock: could not bind to address [::]:80
178
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
179
no listening sockets available, shutting down
180
Unable to open logs
181
</pre>
182
** Then edit @/usr/local/apache2/conf/httpd.conf@,
183
<pre>
184
$ xemacs /usr/local/apache2/conf/httpd.conf 
185
</pre>
186
** and change,
187
<pre>
188
Listen 80 
189
</pre>
190
** to a port that is not in use e.g.
191
<pre>
192
Listen 9090
193
</pre>
194
** and start Apache,
195
<pre>
196
$ /usr/local/apache2/bin/apachectl -k start
197
</pre>
198
* Browse to http://localhost:8080 (or whatever port you specified above) and you should see @It works!"@
199
200
Useful files:
201
202
* Configuration: @/usr/local/apache2/conf/httpd.conf@
203
* Error log: @/usr/local/apache2/logs/error_log@
204
205
h2. mod_wsgi deployment
206
207 17 Jackson, Mike
mod_wsgi (http://code.google.com/p/modwsgi/) is an Apache module allowing the hosting of Python applications which suppport Python's WSGI (Web Server Gateway Interface). For full deployment information, see http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide, http://code.google.com/p/modwsgi/wiki/InstallationInstructions and  http://code.google.com/p/modwsgi/wiki/InstallationIssues
208 1 Jackson, Mike
209 17 Jackson, Mike
* Download latest release (July 2010),
210 1 Jackson, Mike
<pre>
211
$ wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz
212
</pre>
213
* Extract,
214
<pre>
215
$ gunzip mod_wsgi-3.3.tar.gz 
216
$ tar -xf mod_wsgi-3.3.tar
217
$ cd mod_wsgi-3.3
218
</pre>
219 17 Jackson, Mike
* Set Python library path. 
220
** If you have Python 2.7 installed and it is your default Python then skip this step. 
221
** If you are using Python 2.7 in the MAUS software then set @LD_PYTHON_PATH@ to the location of its libraries e.g. if using Python bundled with MAUS, set:
222 1 Jackson, Mike
<pre>
223 17 Jackson, Mike
$ export LD_LIBRARY_PATH=/home/user/maus/third_party/install/lib/
224 1 Jackson, Mike
</pre>
225 13 Jackson, Mike
* Configure,
226 17 Jackson, Mike
** If you have Python 2.7 installed and it is your default Python then run,
227 1 Jackson, Mike
<pre>
228 17 Jackson, Mike
$ ./configure --with-apxs=/usr/local/apache2/bin/apxs
229 1 Jackson, Mike
</pre>
230 17 Jackson, Mike
** If you are using Python 2.7 in the MAUS software you need to provide the path, so run,
231
<pre>
232
$ ./configure --with-apxs=/usr/local/apache2/bin/apxs
233
  --with-python=/home/user/maus/third_party/install/bin/python2.7
234
</pre>
235 1 Jackson, Mike
** If you get an error like:
236
<pre>
237 17 Jackson, Mike
/home/user/maus/third_party/install/bin/python2.7: error while loading 
238 1 Jackson, Mike
shared libraries: libpython2.7.so.1.0: cannot open shared object file: 
239
No such file or directory
240
</pre>
241
** Then set the @LD_LIBRARY_PATH@ as above.
242
** If you get an error like:
243
<pre>
244
checking for apxs2... no
245
checking for apxs... no
246
checking Apache version... ./configure: line 1704: apxs: command not found
247
./configure: line 1704: apxs: command not found
248
./configure: line 1705: apxs: command not found
249
./configure: line 1708: /: is a directory
250
251 17 Jackson, Mike
checking for python... /home/user/maus/third_party/install/bin/python
252 1 Jackson, Mike
./configure: line 1877: apxs: command not found
253
configure: creating ./config.status
254
config.status: error: cannot find input file: Makefile.in
255
</pre>
256 17 Jackson, Mike
** Then you forgot to provide the path to Apache's @apxs@ command,
257 1 Jackson, Mike
* Compile,
258
<pre>
259
$ make
260
</pre>
261
* Install,
262
<pre>
263
$ make install
264
</pre>
265
* A @mod_wsgi.so@ library is installed in @/usr/local/apache2/modules@.
266
* Configure Apache, edit @/usr/local/apache2/conf/httpd.conf@,
267
<pre>
268
$ xemacs /usr/local/apache2/conf/httpd.conf 
269
</pre>
270
* and add,
271
<pre>
272
LoadModule wsgi_module modules/mod_wsgi.so
273
</pre>
274 17 Jackson, Mike
* Set the @LD_LIBRARY_PATH@ in the Apache environment.
275
** If you have Python 2.7 installed and it is your default Python then skip this step. 
276
** If you are using Python 2.7 in the MAUS software then set @LD_PYTHON_PATH@ to the location of its libraries e.g. if using Python bundled with MAUS, then:
277
*** Edit @/usr/local/apache2/bin/envvars@ and add a line to set the Python library path e.g.
278 1 Jackson, Mike
<pre>
279 17 Jackson, Mike
LD_LIBRARY_PATH="/home/user/maus/third_party/install/lib/:$LD_LIBRARY_PATH" 
280 1 Jackson, Mike
</pre>
281 17 Jackson, Mike
*** Ensure that the permissions in this path allow group and world read and execute permission (755) e.g.:
282 1 Jackson, Mike
<pre>
283
$ ls -l /home
284 17 Jackson, Mike
drwxr-xr-x 26 user group 4096 Mar  6 10:08 user
285 1 Jackson, Mike
</pre>
286
** If not then set these,
287
<pre>
288 17 Jackson, Mike
$ chmod go+rx /home/user
289 1 Jackson, Mike
</pre>
290
* Restart Apache,
291
<pre>
292
$ /usr/local/apache2/bin/apachectl restart
293
</pre>
294
* If all is well you should see, in @/usr/local/apache2/logs/error_log@ a line like,
295
<pre>
296
[Tue Feb 07 18:50:37 2012] [notice] Apache/2.2.22 (Unix) mod_wsgi/3.3 
297
Python/2.7.2 configured -- resuming normal operations
298
</pre>
299
* If you see an error like,
300
<pre>
301
[Tue Feb 07 18:46:40 2012] [notice] SIGHUP received.  Attempting to restart
302 2 Jackson, Mike
httpd: Syntax error on line 55 of /usr/local/apache2/conf/httpd.conf: Cannot 
303
load /usr/local/apache2/modules/mod_wsgi.so into server: 
304
libpython2.7.so.1.0: cannot open shared object file: No such file or directory
305
</pre>
306
** then you have to set the @LD_LIBRARY_PATH@ as above.
307
* If you see an error like,
308
<pre>
309
Could not find platform independent libraries <prefix>
310
Could not find platform dependent libraries <exec_prefix>
311
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
312
ImportError: No module named site
313
</pre>
314
** then it is likely you did not set the file permissions for the directory in which Python is as described above.
315
* Clean up,
316
<pre>
317
$ make clean
318
</pre>
319
320
To check your installation (following http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation),
321
322
* List server information,
323
<pre>
324
$ /usr/local/apache2/bin/httpd  -V
325
Server version: Apache/2.2.22 (Unix)
326
...
327
Server MPM:     Prefork
328
  threaded:     no
329 1 Jackson, Mike
    forked:     yes (variable process count)
330 2 Jackson, Mike
Server compiled with....
331
 -D APACHE_MPM_DIR="server/mpm/prefork"
332
...
333
</pre>
334
** Important information is the version and prefork settings,
335
* List compiled-in modules,
336
<pre>
337
$ /usr/local/apache2/bin/httpd  -l
338
Compiled in modules:
339
...
340 1 Jackson, Mike
  prefork.c
341 2 Jackson, Mike
</pre>
342
** You should see @prefork.c@.
343
* List dynamically-loaded modules,
344
<pre>
345
$ /usr/local/apache2/bin/httpd  -M
346
 mpm_prefork_module (static)
347
 ...
348
 wsgi_module (shared)
349
 ...
350
</pre>
351 1 Jackson, Mike
** You should see @wsgi_module@.
352
** If this fails with,
353
<pre>
354
httpd: Syntax error on line 55 of /usr/local/apache2/conf/httpd.conf: 
355
Cannot load /usr/local/apache2/modules/mod_wsgi.so into server: 
356
libpython2.7.so.1.0: cannot open shared object file: No such file or directory
357
</pre>
358
** Then set your @LD_LIBRARY_PATH@ as above and try again,
359
<pre>
360 20 Jackson, Mike
$ export LD_LIBRARY_PATH="/home/user/maus/third_party/install/lib/:$LD_LIBRARY_PATH"
361 1 Jackson, Mike
$ /usr/local/apache2/bin/httpd -M
362
Loaded Modules:
363
...
364 2 Jackson, Mike
</pre>
365
* List modules linked to by @mod_wsgi@:
366
<pre>
367
$ ldd /usr/local/apache2/modules/mod_wsgi.so
368
...
369 20 Jackson, Mike
libpython2.7.so.1.0 => /home/user/maus/third_party/install/lib/libpython2.7.so.1.0 
370 2 Jackson, Mike
(0x00110000)
371
...
372 1 Jackson, Mike
</pre>
373 2 Jackson, Mike
** You should see the link to your Python library.
374
375 18 Jackson, Mike
h2. Deploy the MAUS Django web front-end
376 2 Jackson, Mike
377
* Check-out the MAUS Django code,
378 5 Jackson, Mike
<pre>
379 2 Jackson, Mike
$ bzr branch -v lp:~michaelj-h/maus-apps/devel maus-apps
380 3 Jackson, Mike
</pre>
381 17 Jackson, Mike
* Set up environment,
382 6 Jackson, Mike
<pre>
383 8 Jackson, Mike
$ cd maus-apps
384 4 Jackson, Mike
$ ./configure
385 6 Jackson, Mike
$ ./install.sh
386 3 Jackson, Mike
</pre>
387
* Copy a couple of sample images,
388 6 Jackson, Mike
<pre>
389 3 Jackson, Mike
$ cp images/* media/raw
390
</pre>
391 2 Jackson, Mike
392 17 Jackson, Mike
* Log in as super-user e.g. using @sudo su -@ or @su@.
393 2 Jackson, Mike
* Edit Apache 2.2 environment, so it has access to the MAUS and MAUS web-front end environments (in particular all the Python libraries that have been easy_installed):
394
<pre>
395
$ xemacs -nw /usr/local/apache2/bin/envvars
396
</pre>
397
* Add, changing to use your own paths,
398
<pre>
399 20 Jackson, Mike
source /home/user/maus/env.sh 
400
source /home/user/maus-apps/env.sh
401 8 Jackson, Mike
</pre>
402
* Ensure that the permissions in to your paths allow group and world read and execute permission (755) e.g.:
403
<pre>
404
$ ls -l /home
405 20 Jackson, Mike
drwxr-xr-x 26 user group 4096 Mar  6 10:08 user
406 8 Jackson, Mike
</pre>
407
** If not then set these,
408 2 Jackson, Mike
<pre>
409
$ chmod go+rx /home/michaelj
410 1 Jackson, Mike
</pre>
411 17 Jackson, Mike
* Edit Apache 2 configuration,
412
<pre>
413
$ xemacs -nw /usr/local/apache2/conf/httpd.conf
414
</pre>
415
Add,
416
<pre>
417
WSGIScriptAlias / ${MAUS_WEB_DIR}/apache/django.wsgi  
418
 
419
# Location of django.wsgi 
420
<Directory ${MAUS_WEB_DIR}/apache> 
421
Order deny,allow  
422
Allow from all  
423
</Directory> 
424
</pre>
425
* where:
426
** @/@ specifies the root URL - so all URL requests will be directed to Django.
427
** @/...@ - location of WSGI file within the MAUS Django project.
428 12 Jackson, Mike
* Restart Apache 2.2,
429 2 Jackson, Mike
<pre>
430
$ /usr/local/apache2/bin/apachectl restart
431
</pre>
432
* Test,
433
** Visit http://localhost:8080/maus/, remembering to change the port number if you use a custom port.
434 17 Jackson, Mike
435
For general information on Django deployment under Apache 2.2/mod_wsgi, see https://docs.djangoproject.com/en/1.3/howto/deployment/modwsgi/ and  http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango.