Project

General

Profile

MAUSDjangoApache » History » Version 22

Jackson, Mike, 06 March 2012 16:22

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