Project

General

Profile

MAUSDjangoApache » History » Version 23

Jackson, Mike, 06 March 2012 16:23

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