Lexos Server Deployment Guide - WheatonCS/Lexos GitHub Wiki

Lexos Server Deployment Guide

To Update the server with the latest branch, run this code ONLY

  • Setup the server environment.

    • Download the latest version of Anaconda; install it and make sure it is added to the path.
    • Make sure node JS and NPM are installed and up to date. You can install node JS with the following commands: curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - Followed by the command: sudo apt install nodejs
    • Install apache2 and its dev packages. sudo apt install apache2 apache2-dev
    • Install git. sudo apt install git

Setup Lexos Repo

  • Run this section to update to latest version if server is already configured
    • (Don't forget to remove the old folder before downloading the new one) .wsgi and apache2.conf must be modified as necessary if application paths change.
    • Download the branch you want to deploy as a zip file and unzip it. You can put the unzipped folder anywhere you want as long as you can find it. Alternatively, if you want to sync and keep the server always consistent with newest branch, you can git clone the repo. But you will need to add SSH Key before you do so.
    • Go to the Lexos directory and create a virtual environment. python -m venv env
    • Activate the new virtual environment. (Note: once you close and reopen the terminal, you may have to reactivate the virtual environment.) source env/bin/activate
    • Make sure you have the most recent pip. pip install --upgrade pip
    • Install Python requirements. pip install -r requirements.txt
    • Install mod_wsgi package. pip install mod_wsgi
    • Go to Lexos/lexos/static and install javascript libraries. npm install
    • Stay in the directory and run the following command to get the secret key. head -c 24 /dev/urandom > secret_key
    • This step is tricky and it is related to our current software structure. Go to Lexos/lexos directory, create a folder called lexos and move all other folders inside it besides templates and static.

Create an application.wsgi file and paste the following code into it

import sys
# Use your actual Lexos path
application_path = "home/user/your_Lexos_path/Lexos/lexos"

# Append important paths.
sys.path.insert(0, application_path)

from application import app as application

Configure Apache server

  • Go to Apache configuration folder and go to sites-available cd /etc/apache2/sites-available/

  • Replace the content in 000-default.conf with the following code:

    <VirtualHost *:80>
         ServerName lexos.com
         WSGIDaemonProcess lexos user=www-data group=www-data threads=number_of_threads
         WSGIScriptAlias / /directory of your application.wsgi file/application.wsgi
    
         <Directory /directory of your lexos app/Lexos/lexos>
             WSGIProcessGroup lexos
             WSGIApplicationGroup %{GLOBAL}
             Require all granted
         </Directory>
    </VirtualHost> 
    
  • Next, go to etc/apache2/ and edit apache2.conf. Go to the line that says <Directory />, and change the line below which says Require all denied to Require all granted.

    • Make sure you have the virtual environment activated (in your terminal it should say (env) before your user name). Run command: mod_wsgi-express module-config This shall return two lines similar to the following:
    LoadModule wsgi_module "/home/weiqi/Git/Lexos/env/lib/python3.7/site-packages/mod_wsgi/server/mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so"
    WSGIPythonHome "/home/weiqi/Git/Lexos/env"
  • Paste both lines to the bottom of the apache2.conf file.

  • Final step and debug

    • Once you are done with all steps above run the following command to restart Apache server to apply changes

    sudo service apache2 restart

    • If you need to debug the server, the error log can be found at /var/log/apache2/error.log (Use sudo su to get permission to access the folder if needed.)

    • You must run the sudo service apache2 restart every time a change is made to the configuration file. This is what applies your changes.

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