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

Installation using PyCharm Professional Edition on Host OS and Ubuntu Server in VirtualBox

Set up Virtual Machine

  • Create VirtualBox VM with Ubuntu Server 64bit In the Ubuntu Server Setup, only select 'openSSH server' when asked which packages should be installed.

  • Add a Host-only network adapter:

    • VM Settings -> Network -> Adapter 2: Host-only adapter
    • Find what the adapter is called in the guest OS by typing ip link (probably eth1 or enp0s8, in the example we'll proceed with eth1)
    • Add the following lines to /etc/network/interfaces in the guest OS (sudo required):
auto eth1
iface eth1 inet dhcp
  • Enable this adapter: sudo ifup eth1 Find IP of VM (ifconfig, look for interface eth1) Something like: 192.168.56.102

  • Add the following line to the /etc/hosts file of the host OS: (C:\Windows\System32\drivers\etc\hosts on Windows, root permissions required) 192.168.56.102 revue-dev (make sure to use the correct IP address)

  • You can now SSH from your host to the VM using: ssh <username>@revue-dev This way, it's easier to use the clipboard etc.

Set up Database

  • Run the following commands to install PostgreSQL and PhpPgAdmin:
sudo apt-get update
sudo apt-get install postgresql
sudo apt-get install phppgadmin
  • Configure PhpPgAdmin
    • Uncomment the line allow from all from the file /etc/apache2/conf.d/phppgadmin.
    • Copy /etc/apache2/conf.d/phppgadmin to /etc/apache2/conf-available/phppgadmin.conf
    • In newer versions, conf.d doesn't exist anymore, and neither does the line allow from all. Just comment out the Require local line in both /etc/apache2/conf-enabled/phppgadmin.conf and /etc/apache2/conf-available/phppgadmin.conf
    • Enable this configuration:
sudo a2enconf phppgadmin
sudo service apache2 reload
  • Prepare the database for this project
sudo -u postgres createuser --superuser $USER
sudo -u posgres psql
	\password <username>
	**password**
	**password once more**
	\q
  • browse to revue-dev/phppgadmin
  • Log in with the credentials you just entered
    • Create a database (e.g. 'revue-dev')
    • In this database create all schemas (alembic can't do this on its own). At the time of writing, you need content, mail and general

Set up working environment

  • Install git and create a SSH Key for you Guest OS
sudo apt-get install git
ssh-keygen -t rsa -b 4096 -C "[email protected]"
git clone [email protected]:VTK-Revue/revue-flask-server.git 
  • Install required packages and create a virtual environment
sudo apt-get install python3 libpq-dev python3-pip
sudo apt-get install virtualenvwrapper # or sudo pip install virtualenvwrapper
export WORKON_HOME=~/venvs
mkdir -p $WORKON_HOME
source /usr/local/bin/virtualenvwrapper.sh # otherwise mkvirtualenv won't be recognized as a command
echo "source \"/usr/local/bin/virtualenvwrapper.sh\"" >> ~/.bashrc # always source virtualenvwrapper
mkvirtualenv -a ./revue-flask-server --python /usr/bin/python3 revue-flask-server
  • Configure the virtual environment so it can access the database
    • Add to ~/venvs/revue-flask-server/bin/postactivate:
export SECRET_KEY='<sercret_key>'
export DATABASE_URL='postgresql://<database_user>:<database_user_password>@localhost/<database_name>'
export APP_SETTINGS="config.<config_settings_class>
* secret_key s a secret key used to provide a unique salt for hash functions.
* database_user is the database user you created (in this tutorial the linux username)
* database_user_password is the password you gave this database user
* database_name is the name of the database you created in phppgadmin
* You can leave config_settings_class at DevelopmentConfig for now.

Configure PyCharm on Host OS

This guide uses funcationalities that are only available the professional edition of PyCharm. As a student, you can get this software for educational purposes (like the development of this project).

  • Create a new empty pure Python project
  • Set the connection with the VM at Tools - Deployment - Configuration
    • Add server (SFTP)
    • SFTP Host: hostname you used in /etc/hosts file (revue-dev)
    • set root path to /home/
    • Mappings:
      • local path = project folder
      • deployment path: /revue-flask-server
      • Use this server as default!
  • Enable automatic upload etc. at Tools - Deployment - Options. Suggested settings:
    • Always upload changed files automatically to default server
    • upload external changes
    • compare timestamp & size when uploading over newer file
    • notify about remote changes
  • Download files for the first time to the PyCharm Project by right clicking on the root folder and selecting Deployment - Download
  • Use the Guest OS' interpreter
    • File - project settings - Project: revue-flask-server - Project Interpreter
      • Choose: Add remote
        • host: revue-dev (the one you choose at the /etc/hosts file)
        • python interpreter path: /home/<username>/venvs/revue-flask-server/bin/python
  • Upon opening a source file for the first time in PyCharm, you'll be asked to install requirements. If not, you can do this manually by running pip install -r requirements.txt.

Create tables

Every time you login to the Guest OS, you can run workon revue-flask-server to activate the virtual environment. Your session's pwd will be changed to the project directory as well. When the database structure needs to be updated, run python manage.py db upgrade in this virtual environment.

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