Project

General

Profile

MAUSDjangoApache » History » Version 19

Jackson, Mike, 06 March 2012 14:30

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