old_installation_guide - VTK-Revue/revue-flask-server GitHub Wiki

Installation guide

This guide will help you installing the revue-flask server. The guide is written for and tested with a clean installation of Ubuntu 14.04 LTS.

1. Requirements

First we need to install some programs.

Apache

On Ubuntu/Debian, install Apache from the official repositories:

sudo apt-get install apache2

PostgreSQL

Now we will install a postgreSQL database.

sudo apt-get install postgresql postgresql-contrib

When running Ubuntu, this command also instantiates a new database cluster called main in /var/lib/postgresql/9.3/main. On other OS you might need to do this yourself (check pg_createcluser for ubuntulike OS and initdb for others).

Create a user for the postgres database (with $USER, a username of your choice):

sudo -u postgres createuser --superuser $USER
sudo -u postgres psql

In the PostgreSQL shell:

\password $USER

PhpPgAdmin (not required, but very handy)

If you want to use phpPgAdmin you will need to install php and its php_pgsql module.

sudo apt-get install php5 php5-pgsql libapache2-mod-php5

Install PhpPgAdmin by downloading the tar into /var/www and extracting it, rename the folder to phpPgAdmin and remove the tar again.

cd /var/www
sudo wget http://downloads.sourceforge.net/phppgadmin/phpPgAdmin-5.1.tar.gz
sudo tar xvf phpPgAdmin-5.1.tar.gz
sudo mv phpPgAdmin-5.1 phpPgAdmin
sudo rm phpPgAdmin-5.1.tar.gz

Also make sure you do the following changes to the config.inc.php file in the phpPgAdmin/conf directory:

Change respectively:

$conf['servers'][0]['desc'] = 'PostgreSQL';
$conf['servers'][0]['host'] = '';

to

$conf['servers'][0]['desc'] = 'Localhost';
$conf['servers'][0]['host'] = 'localhost';

Finaly create a virtual host with apache to access PhpPgAdmin via your browser:

sudo nano /etc/apache2/sites-available/phpPgAdmin.conf

Paste the next into the .conf file:

<VirtualHost *:80>
    ServerName phpPgAdmin

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/phpPgAdmin

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Now enable the newly created site en reload apache (You might see some warnings, but they don't harm):

sudo a2ensite phpPgAdmin.conf
sudo service apache2 reload

Add the next line to your /etc/hosts

127.0.0.1 phpPgAdmin

This will redirect your browser to the virtualhost of phpPgAdmin. Just surf to phppgadmin/ and login with your created user.

Python

We also need two python packages installed on our system:

sudo apt-get install python3-dev libpq-dev

Now we are ready to get the system files.

2. Getting the repository files

Install git on your system. On Ubuntu/Debian:

sudo apt-get install git-core

Create your application source folder (e.g. ~/projects/RevueFlaskServer) and clone the repository.

mkdir $<path_to_source>
cd $<path_to_source>
mkdir application
cd application
git clone https://github.com/VTK-Revue/revue-flask-server.git .

3. Installing and configuring Virtualenv

To keep your current system unaffected we will use a virtual environment: a separate installation of python and our additional dependencies. This way it is also possible to use different versions of python for different projects on the same system.

sudo pip install virtualenvwrapper
which python3
mkvirtualenv --python=/usr/local/bin/python3 revue-flask-server
vi $VIRTUAL_ENV/bin/postactivate

Add the following line:

cd <path-to-source>

Every time you want to work on the project you have to activate the virtual environment:

workon revue-flask-server

To get started, install all dependencies into the virtual environment:

pip install -r <path_to_source>/requirements.txt

4. Setting up Configurations

Create a new postgresql user (with commandline or through phpPgAdmin), create a new database and grant this new user all the rights to this database.

Now setup the environment variables in the following file:

vi $VIRTUAL_ENV/bin/postactivate

Add

export SECRET_KEY='<sercret_key>'
export DATABASE_URL='postgresql://<database_user>:<database_user_password>@localhost/<database_name>'
export APP_SETTINGS="config.<config_settings_class>

Edit the '<...>' to the values you choose/created before. <sercret_key>: Is a secret key used to provide a unique salt for hash functions. <database_user>, <database_user_password>, <database_name>: Are the values from the user/database you created before. <config_settings_class>: Is the class of the app settings you want to load. (DevelopmentConfig, ProductionConfig,...) The classes can be found in config.py.

5. Running

You can now run the application on your local system by running

python <path_to_source>/application/revue_dev.py

You can view the server in action by opening http://127.0.0.1:5000/ in your browser.

If you want to host the application on your network, proceed to step 6 to set up Apache correctly. Otherwise the installation is finished.

6. Setting up Apache

To run a Python application in Apache we need to install the WSGI module:

sudo apt-get install libapache2-mod-wsgi

This module will read a *.wsgi file in your application directory and create a process to run it. Create a file application.wsgi in your application source directory (the directory that contains the application/ and venv/ directories). Paste to following text in it:

import os, sys
VIRTUALENV_DIR = '$<path_to_source>/venv'
PROJECT_DIR = '$<path_to_source>/application'
activate_this = os.path.join(VIRTUALENV_DIR, 'bin', 'activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
sys.path.append(PROJECT_DIR)
from revue_dev import app as application

Make sure you change the <path_to_source> to the path of your source folder. Now we are going to setup the apache host. First we create a directory for the log files:

mkdir log

We will now create the Apache configuration file.

cd /etc/apache2/sites-available

Create a file called <application_name>.conf (choose your own application name) and paste the following code into it:

<VirtualHost *:80>
    ServerName <application_name>

    WSGIDaemonProcess <application_name> user=www-data group=www-data threads=5
    WSGIScriptAlias / <path_to_source>/application.wsgi
    WSGIScriptReloading On

    <Directory <path_to_source>/application>
        WSGIProcessGroup revue_dev
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>

    LogLevel warn
    ErrorLog <path_to_source>/log/error.log
    CustomLog P<path_to_source>/log/access.log combined

</VirtualHost>

Now enable your site:

a2ensite <application_name>.conf

and restart Apache:

service apache2 reload

Finally, edit your hosts file (/etc/hosts) to redirect <application_name> to your local host. Insert the following line: 127.0.0.1 <application_name>

Now you can view the application by navigating your browser to <application_name>.

⚠️ **GitHub.com Fallback** ⚠️