How to deploy the MAUS web-front end¶
This is now done automatically as part of the MAUS build and these pages are stored for historical purposes
- Table of contents
- How to deploy the MAUS web-front end
This page describes how to install and run the MAUS web front-end.
- 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.
- 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.
Install Python 2.7 and related packages¶
If you have downloaded and built the MAUS software (which comes with Python 2.7 and Python setuptools) then go down to Install ImageMagick.
To install Python (2.7.2) by building it from its source code:
- Log in as a super-user by using
sudo su -
orsu
. - Get the Python 2.7 source distribution and unpack it,
$ wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz $ mv Python-2.7.2.tgz Python-2.7.2.tar.gz $ gunzip Python-2.7.2.tar.gz $ tar -xf Python-2.7.2.tar $ cd Python-2.7.2
- Configure,
$ ./configure
- Build,
$ make
- Install,
$ make install
For more information, see http://www.python.org/getit/releases/2.7//
Install Python setuptools¶
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.
To install Python setuptools (0.6c11) for Python 2.7:
- Log in as a super-user by using
sudo su -
orsu
. - Get the setuptools egg,
$ wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg#md5=fe1f997bc722265116870bc7919059ea
- Execute the egg,
$ sh setuptools-0.6c11-py2.7.egg
Install ImageMagick¶
The ImageMagick library (http://www.imagemagick.org/script/index.php) is used to convert between image types.
Check to see if you already have this, as it is a commonly installed tool,
$ /usr/local/bin/convert -h Version: ImageMagick 6.7.4-0 2011-12-13 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC Features: OpenMP
If so then go down to Install Django, MagickWand and Python Image Library packages.
To install ImageMagick (6.7.4),
- Log in as a super-user by using
sudo su -
orsu
. - EITHER install ImageMagick RPM:
$ wget http://www.imagemagick.org/download/linux/CentOS/i386/ImageMagick-6.7.5-10.i386.rpm $ sudo rpm -Uvh ImageMagick-6.7.5-10.i386.rpm
- OR build from source:
- Get and unpack ImageMagick,
$ wget http://www.imagemagick.org/download/ImageMagick.tar.gz $ gunzip ImageMagick.tar.gz $ tar -xf ImageMagick.tar $ cd ImageMagick-6.7.4-0/
- Configure,
$ ./configure
- Make,
$ make
- Install,
$ make install
- This places libraries in
/usr/local/lib
.
- This places libraries in
- Cache the libraries,
$ /sbin/ldconfig /usr/local/lib
- This avoids problems with libraries not being found by Python's magickwand library.
- Get and unpack ImageMagick,
- Check,
$ /usr/local/bin/convert -h Version: ImageMagick 6.7.4-0 2011-12-13 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC Features: OpenMP
Install Django, MagickWand and Python Image Library packages¶
- Django (https://www.djangoproject.com/) is a Python package for developing web applications.
- MagickWand (http://pypi.python.org/pypi/magickwand) is a Python package allowing ImageMagick to be used from within Python.
- Python Image Library (http://www.pythonware.com/products/pil/) is a package of image manipulation utilities.
To install the current versions of these Python packages using easy_install
:
- 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 -
orsu
. - Run,
$ easy_install django $ easy_install magickwand $ easy_install pil
Check MagickWand:
- Start Python,
$ python $ import magickwand $ from magickwand.image import Image ...
- If you get an error like,
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "build/bdist.linux-i686/egg/magickwand/image.py", line 2, in <module> File "build/bdist.linux-i686/egg/magickwand/api/__init__.py", line 1, in <module> # File "build/bdist.linux-i686/egg/magickwand/api/lib.py", line 11, in <module> File "/home/user/maus/third_party/install/lib/python2.7/ctypes/__init__.py", line 353, in __init__ self._handle = _dlopen(self._name, mode) OSError: libMagickWand.so.5: cannot open shared object file: No such file or directory
- then, as super-user, run
ldconfig
:$ /sbin/ldconfig /usr/local/lib
Install Apache 2.2¶
Apache 2.2 (http://httpd.apache.org/) is an HTTP server.
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.
To install Apache 2.2,
- Log in as a super-user by using
sudo su -
orsu
. - Download,
$ wget http://mirrors.ukfast.co.uk/sites/ftp.apache.org//httpd/httpd-2.2.22.tar.gz
- Extract,
$ gzip -d httpd-2.2.22.tar.gz $ tar xvf httpd-2.2.22.tar $ cd httpd-2.2.22
- Configure,
$ ./configure
- This uses a default installation directory of
/usr/local/apache2
.
- This uses a default installation directory of
- Compile,
$ make
- Install,
$ make install
- Start-up server,
$ /usr/local/apache2/bin/apachectl -k start
- If you get an error like,
(98)Address already in use: make_sock: could not bind to address [::]:80 (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down Unable to open logs
- Then edit
/usr/local/apache2/conf/httpd.conf
and change,Listen 80
- to a port that is not in use e.g.
Listen 9090
- and try to start Apache again as described above.
- If you get an error like,
- Browse to http://localhost:8080 (or whatever port you specified above) and you should see
It works!"
More information:
- Apache 2 configuration file:
/usr/local/apache2/conf/httpd.conf
- Error log:
/usr/local/apache2/logs/error_log
- Installation instructions: http://httpd.apache.org/docs/current/install.html
Install mod_wsgi¶
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).
To install mod_wsgi (July 2010 release) under Apache 2.2,
- Log in as a super-user by using
sudo su -
orsu
. - Download release,
$ wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz
- Extract,
$ gunzip mod_wsgi-3.3.tar.gz $ tar -xf mod_wsgi-3.3.tar $ cd mod_wsgi-3.3
- Set Python library path,
- If you are not using the MAUS software to provide Python 2.7, then skip this step.
- If you are using the MAUS software to provide Python 2.7, then set
LD_PYTHON_PATH
to the location of its libraries e.g.:$ export LD_LIBRARY_PATH=/home/user/maus/third_party/install/lib/
- Configure,
- If you installed Python 2.7 then run,
$ ./configure --with-apxs=/usr/local/apache2/bin/apxs
- If you are using the MAUS software to provide Python 2.7, you need to provide the path, so run,
$ ./configure --with-apxs=/usr/local/apache2/bin/apxs --with-python=/home/user/maus/third_party/install/bin/python2.7
- If you get an error like:
/home/user/maus/third_party/install/bin/python2.7: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
- then set the
LD_LIBRARY_PATH
as above. - If you get an error like:
checking for apxs2... no checking for apxs... no checking Apache version... ./configure: line 1704: apxs: command not found ./configure: line 1704: apxs: command not found ./configure: line 1705: apxs: command not found ./configure: line 1708: /: is a directory checking for python... /home/user/maus/third_party/install/bin/python ./configure: line 1877: apxs: command not found configure: creating ./config.status config.status: error: cannot find input file: Makefile.in
- then you forgot to provide the path to Apache's
apxs
command,
- If you installed Python 2.7 then run,
- Compile,
$ make
- Install,
$ make install
- A
mod_wsgi.so
library is installed in/usr/local/apache2/modules
. - Configure Apache:
- Edit
/usr/local/apache2/conf/httpd.conf
- Look for the comment,
# Example # LoadModule foo_module modules/mod_foo.so #
- Under this comment, add,
LoadModule wsgi_module modules/mod_wsgi.so
- Edit
- Set the
LD_LIBRARY_PATH
in the Apache environment,- If you are not using the MAUS software to provide Python 2.7, then skip this step.
- If you are using the MAUS software to provide Python 2.7, then set
LD_PYTHON_PATH
to the location of its libraries,- Edit
/usr/local/apache2/bin/envvars
and insert your path on a line before theexport LD_LIBRARY_PATH
line, so the file becomesLD_LIBRARY_PATH="/usr/local/apache2/lib:$LD_LIBRARY_PATH" LD_LIBRARY_PATH="/home/user/maus/third_party/install/lib/:$LD_LIBRARY_PATH" export LD_LIBRARY_PATH
- Ensure that the permissions in your path allow group and world read and execute permission (755),
$ chmod go+rx /home/user
- Edit
- Restart Apache,
$ /usr/local/apache2/bin/apachectl restart
- If all is well you should see, in
/usr/local/apache2/logs/error_log
, a line like,[Tue Feb 07 18:50:37 2012] [notice] Apache/2.2.22 (Unix) mod_wsgi/3.3 Python/2.7.2 configured -- resuming normal operations
- If you see an error like,
[Tue Feb 07 18:46:40 2012] [notice] SIGHUP received. Attempting to restart httpd: Syntax error on line 55 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/mod_wsgi.so into server: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
- then you have to set the
LD_LIBRARY_PATH
as above.
- then you have to set the
- If you see an error like,
Could not find platform independent libraries <prefix> Could not find platform dependent libraries <exec_prefix> Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] ImportError: No module named site
- then it is likely you did not set the file permissions for the directory in which Python is as described above.
- Clean up,
$ make clean
To check your installation,
- List server information,
$ /usr/local/apache2/bin/httpd -V Server version: Apache/2.2.22 (Unix) ... Server MPM: Prefork threaded: no forked: yes (variable process count) Server compiled with.... -D APACHE_MPM_DIR="server/mpm/prefork" ...
- Important information is the version and prefork settings,
- List compiled-in modules,
$ /usr/local/apache2/bin/httpd -l Compiled in modules: ... prefork.c
- You should see
prefork.c
.
- You should see
- List dynamically-loaded modules,
$ /usr/local/apache2/bin/httpd -M mpm_prefork_module (static) ... wsgi_module (shared) ...
- You should see
wsgi_module
. - If this fails with,
httpd: Syntax error on line 55 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/mod_wsgi.so into server: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
- Then set your
LD_LIBRARY_PATH
as above and try again,$ export LD_LIBRARY_PATH="/home/user/maus/third_party/install/lib/:$LD_LIBRARY_PATH" $ /usr/local/apache2/bin/httpd -M Loaded Modules: ...
- You should see
- List modules linked to by
mod_wsgi
:$ ldd /usr/local/apache2/modules/mod_wsgi.so ... libpython2.7.so.1.0 => /home/user/maus/third_party/install/lib/libpython2.7.so.1.0 (0x00110000) ...
- You should see the link to your Python library.
More information:
- http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide
- http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation
- http://code.google.com/p/modwsgi/wiki/InstallationInstructions
- http://code.google.com/p/modwsgi/wiki/InstallationIssues
Install the MAUS web front-end¶
Check-out the MAUS Django code,
$ bzr branch -v lp:maus-apps $ cd maus-apps
You can run the MAUS web front-end one of two ways:
- Run under the Django web server
- Run under the Apache web server (if you have set Apache up as described above)
Run the web front-end under the Django web server¶
- Create the environment script,
- If you are not using the MAUS software to provide Python 2.7:
$ ./configure
- If you are using the MAUS software to provide Python 2.7:
$ ./configure --with-maus
- If you are not using the MAUS software to provide Python 2.7:
- Set up the environment,
- 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.
$ source /home/user/maus/env.sh
- Set up the MAUS web front-end environment:
$ source env.sh
- 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.
- Start the Django web server. Run:
$ python src/mausweb/manage.py runserver HOST:PORT
- where
HOST
is your host name andPORT
is the port on which the web server listens. For example$ python src/mausweb/manage.py runserver localhost:9000
- or,
$ python src/mausweb/manage.py runserver maus.epcc.ed.ac.uk:9000
- where
Run the web front-end under the Apache web server¶
- Create the environment script,
- If you are not using the MAUS software to provide Python 2.7:
$ ./configure
- If you are using the MAUS software to provide Python 2.7:
$ ./configure --with-maus
- If you are not using the MAUS software to provide Python 2.7:
- Log in as a super-user by using
sudo su -
orsu
. - Set the paths in the Apache environment, edit
/usr/local/apache2/bin/envvars
:- If you are not using the MAUS software to provide Python 2.7, then add, on a line before the
export LD_LIBRARY_PATH
line, a command to sources the MAUS web front-endenv.sh
script e.g.:source /home/user/maus-apps/env.sh
- If you are using the MAUS software to provide Python 2.7, then add, on lines before the
export LD_LIBRARY_PATH
line, commands to sources the MAUS software and MAUS web front-endenv.sh
scripts e.g.:source /home/user/maus/env.sh source /home/user/maus-apps/env.sh
- Ensure that the permissions in your path allow group and world read and execute permission (755) to these scripts e.g.,
$ chmod go+rx /home/user
- If you are not using the MAUS software to provide Python 2.7, then add, on a line before the
- Edit the Apache 2 configuration,
/usr/local/apache2/conf/httpd.conf
and add to the end of the file:WSGIScriptAlias / ${MAUS_WEB_DIR}/apache/django.wsgi <Directory ${MAUS_WEB_DIR}/apache> Order deny,allow Allow from all </Directory>
- For your information,
/
specifies the root URL - so all URL requests will be directed to Django./...
- location of WSGI file within the MAUS Django project.
- If you are using the web front-end development branch (i.e. you have branched
lp:~michaelj-h/maus-apps/devel
) then before theWSGIScriptAlias / ${MAUS_WEB_DIR}/apache/django.wsgi
line, addAlias /static/ ${MAUS_WEB_MEDIA}/ <Directory ${MAUS_WEB_MEDIA}> Order deny,allow Allow from all </Directory>
- For your information,
- Restart Apache 2.2,
$ /usr/local/apache2/bin/apachectl restart
- https://docs.djangoproject.com/en/1.3/howto/deployment/modwsgi
- http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
Test your installation¶
- Copy a couple of sample images,
$ cp images/* media/raw
- Browse to the URL
http://HOST:PORT/maus
whereHOST
is your host name andPORT
is the port on which the web server listens. For examplehttp://localhost:80/maus/
If using Apache 2 you get an error like the following in the /usr/local/apache2/logs/error_log
:
[Tue Mar 06 17:23:31 2012] [error] [client 127.0.0.1] mod_wsgi (pid=24026): Exception occurred processing WSGI script '/home/mice/MAUS/mike/maus_apps/apache/django.wsgi'. [Tue Mar 06 17:23:31 2012] [error] [client 127.0.0.1] IOError: failed to write data
Then this may be caused by
- Permissions to your MAUS directories specified in
/usr/local/apache2/bin/envvars
not having permission755
. - ImageMagick being an older version than expected by Python's magickwand package, in which case update the version.
- ImageMagick libraries not having been cached, in which case, as
su
, run,/sbin/ldconfig /usr/local/lib
- You have forgotten to
easy_install
one, or more, ofdjango
,magickwand
, orpil
.
Supported images¶
Currently the MAUS web front-end supports any image formats with extensions supported by Matplotlib or
PyROOT and handled by MagickWand image converter:
- PostScript: "ps"
- Enhanced PostScript: "eps"
- PNG: "png"
- PDF: "pdf"
- GIF: "gif"
- JPEG: "jpg", "jpeg"
Updated by Rogers, Chris over 10 years ago ยท 9 revisions