OMERO.web walkthrough installation CentOS 7 and IcePy 3.6
=========================================================


For convenience in this walkthrough the main OMERO.web configuration options have been defined as environment variables. When following this walkthrough you can either use your own values, or alternatively source the following file::
    
    OMERO_USER=omero
    WEBPORT=80
    WEBSERVER_NAME=localhost



Create local user omero, homedir :file:`/home/omero` (run as root)::
    
    if [ -z "$(getent passwd omero)" ]; then
    
        useradd -m omero
    
    fi
    
    chmod a+X /home/omero

Install ZeroC IcePy 3.6. IcePy is managed by PyPI and will be installed as a part of OMERO.web requirements (run as root)::
    
    yum -y install \
        gcc \
        gcc-c++ \
        python-devel
    
    yum -y install \
        libdb-utils \
        openssl-devel bzip2-devel expat-devel

Install other dependencies (run as root)::
    
    yum -y install epel-release
    
    yum -y install python-pip
    
    yum -y install \
        python-pillow \
        numpy
    
    
    # install the latest version
    pip install --upgrade pip
    pip install --upgrade virtualenv


Install VirtualEnv - optional (run as root)::
    
    virtualenv /home/omero/omerowebvenv --system-site-packages

Install OMERO.web (run as omero)::
    
    cd /home/omero
    curl -o OMERO.py.zip -L https://downloads.openmicroscopy.org/latest/omero5.3/py.zip
    unzip -q OMERO.py*
    
    zip=$(ls OMERO.py*.zip)
    rm -f $zip
    ln -s OMERO.py-* OMERO.py

Install in the virtualenv created previously (run as root)::
    
    /home/omero/omerowebvenv/bin/pip install --upgrade -r /home/omero/OMERO.py/share/web/requirements-py27.txt

Configure OMERO.web and generate nginx template (run as omero)::
    
    source /home/omero/omerowebvenv/bin/activate
    # By default no value is set for WEBPREFIX but for example it can be set to /omero
    if [[ $WEBPREFIX = *[!\ ]* ]]; then
        /home/omero/OMERO.py/bin/omero config set omero.web.prefix "${WEBPREFIX}"
        /home/omero/OMERO.py/bin/omero config set omero.web.static_url "${WEBPREFIX}/static/"
    fi
    
    /home/omero/OMERO.py/bin/omero config set omero.web.application_server wsgi-tcp
    /home/omero/OMERO.py/bin/omero web config nginx --http "${WEBPORT}" --servername "${WEBSERVER_NAME}" > /home/omero/nginx.conf.tmp
    
    cat /home/omero/nginx.conf.tmp

Install NGINX (run as root)::
    
    yum -y install nginx
    
    sed -i.bak -re 's/( default_server.*)/; #\1/' /etc/nginx/nginx.conf
    if [ -f /etc/nginx/conf.d/default.conf ]; then
        mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.disabled
    fi
    cp /home/omero/nginx.conf.tmp /etc/nginx/conf.d/omeroweb.conf
    
    systemctl enable nginx
    
    systemctl start nginx

Disable SELINUX (run as root)::
    
    if [ $(getenforce) != Disabled ]; then
    
        yum -y install policycoreutils-python
        setsebool -P httpd_read_user_content 1
        setsebool -P httpd_enable_homedirs 1
        semanage port -a -t http_port_t -p tcp 4080
    
    fi

Daemon (run as root)::
    
    Create a file omero-web-systemd.service. See example file below.
    cp omero-web-systemd.service /etc/systemd/system/omero-web.service
    
    systemctl daemon-reload
    
    systemctl enable omero-web.service
    
    systemctl start omero-web.service

omero-web-systemd.service example::
    
    [Unit]
    Description=OMERO.web
    # Not mandatory, Nginx may be running on a different server
    Requires=nginx.service
    After=network.service
    
    [Service]
    User=omero
    Type=forking
    PIDFile=/home/omero/OMERO.py/var/django.pid
    Restart=no
    RestartSec=10
    Environment="PATH=/home/omero/omerowebvenv/venv/bin:/bin:/usr/bin" "WEBBINDIR=/home/omero/OMERO.py/bin"
    ExecStart=/home/omero/omerowebvenv/venv/python $WEBBINDIR/omero web start
    ExecStop=/home/omero/omerowebvenv/venv/python $WEBBINDIR/omero web stop
    
    [Install]
    WantedBy=multi-user.target