Skip to content

Installations

anjalysuresh edited this page Jan 29, 2018 · 38 revisions

Installations

Installing the Server Dependencies for Collaborative Communities project

  1. First thing let’s upgrade the packages:

    sudo apt-get update sudo apt-get -y upgrade

  2. Install mysql and dependencies

    sudo apt-get mysql server

  3. Install nginx

    sudo apt-get -y install nginx

  4. Install supervisor

    Supervisor will start the application server and manage it in case of server crash or restart:

    sudo apt-get -y install supervisor

    Enable and start the Supervisor:

    sudo systemctl enable supervisor

    sudo systemctl start supervisor

  5. Python Virtualenv

    The Django application will be deployed inside a Python Virtualenv,

    sudo apt-get install python3 python3-pip virtualenvwrapper

  6. Create user and database in mysql

    create user 'collabaoration' identified by 'password'; create database collaboration;

  7. Create a new user

    sudo adduser collaboration

  8. Add the user to the list of sudoers:

    sudo adduser community sudo

  9. su - collaboration

  10. Configure the Python3 Virtualenv

    mkvirtualenv --python=/usr/bin/python3 tester

  11. Clone the code repository to virtual environment ,the command prompt will show like below

    (tester) collaboration@edx:~/tester$

    git clone https://github.com/fresearchgroup/Collaboration-System.git

  12. cd project directory

    pip3 install -r requirements.txt

  13. Create the database settings as per project documentation), install django and other modules using the project documentation.

    my.cnf

  14. Migrate the database

    python3 manage.py migrate

  15. Collect the static files

    python3 manage.py collectstatic

  16. Add vm's ip address to allowed hosts in the settings.py of project

  17. Check whether the project is running at ipaddress:8000 of vm

  18. Configure gunicorn

    First install Gunicorn inside the virtualenv:

    pip3 install gunicorn

    Create a file named gunicorn_start inside the bin/ folder:

    cd /home/collaboration/tester/

    sudo vi bin/gunicorn_start

    #! bin/bash

    NAME="Collaboration-System" DIR=/home/collaboration/tester/Collaboration-System USER=collaboration GROUP=collaboration WORKERS=3 BIND=unix:/home/collaboration/tester/run/gunicorn.sock DJANGO_SETTINGS_MODULE=CollaborationSystem.settings DJANGO_WSGI_MODULE=CollaborationSystem.wsgi LOG_LEVEL=error

    cd $DIR source ../bin/activate

    export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE export PYTHONPATH=$PYTHONPATH echo $PYTHONPATH

    exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application
    --name $NAME
    --workers $WORKERS
    --user=$USER
    --group=$GROUP
    --bind=$BIND
    --log-level=$LOG_LEVEL
    --log-file=-

    Make the gunicorn_start file is executable:

    chmod u+x bin/gunicorn_start

    Create a directory named run in /home/collaboration/tester for the unix socket file:

    mkdir run

  19. Configure Supervisor

    Now what we want to do is configure Supervisor to take care of running the gunicorn server.

    First let’s create a folder named logs inside the virtualenv:

    mkdir logs in /home/collaboration/tester

    Create a file to be used to log the application errors:

    touch logs/gunicorn-error.log

    Create a new Supervisor configuration file:

    Collaboration-System.conf in /etc/supervisor/conf.d/

    cd /etc/supervisor/conf.d/

    vi Collaboration-System.conf

    [program:Collaboration-System] command= /home/collaboration/tester/bin/gunicorn_start user=root autostart=true autorestart=true

    redirect_stderr=true stdout_logfile=/home/collaboration/tester/logs/gunicorn-error.log

    Reread Supervisor configuration files and make the new program available:

    sudo supervisorctl reread sudo supervisorctl update

    Check the status:

    sudo supervisorctl status Collaboration-System

    it should give like this

    Collaboration-System RUNNING pid 5200, uptime 0:00:09

    Now you can control your application using Supervisor. If you want to update the source code of your application with a new version, you can pull the code from GitHub and then restart the process:

    sudo supervisorctl restart Collaboration-System

  20. Configure NGINX

    Add a new configuration file named Collaboration System inside /etc/nginx/sites-available/:

    sudo vim /etc/nginx/sites-available/Collaboration-System

upstream app_server {
server unix:/home/collaboration/tester/run/gunicorn.sock fail_timeout=0;
}
server {
listen 8000;
# add here the ip address of your server
# or a domain pointing to that ip (like example.com or www.example.com)
server_name 10.129.26.148;

keepalive_timeout 5;
client_max_body_size 4G;

access_log /home/collaboration/tester/logs/nginx-access.log;
error_log /home/collaboration/tester/logs/nginx-error.log;

location /static/ {
    alias /home/collaboration/tester/Collaboration-System/static/;
}

location /media/ {
   alias /home/collaboration/tester/Collaboration-System/media;
}

# checks for static file, if not found proxy to app
location / {
    try_files $uri @proxy_to_app;
}

location @proxy_to_app {
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $http_host;
  proxy_redirect off;
  proxy_pass http://app_server;
}

}

  1. Create a symbolic link to the sites-enabled dir:

    sudo ln -s /etc/nginx/sites-available/Collaboration-System /etc/nginx/sites-enabled/Collaboration-System

  2. Remove NGINX default website:

    sudo rm /etc/nginx/sites-enabled/default

  3. Restart NGINX:

    sudo service nginx restart

  4. Now open the browser and check the application is working at 10.129.26.148:8000.

  5. A final test is to reboot the machine and see if everything restarts automatically:

    sudo reboot

  6. Steps to be followed to update the application

    ssh [email protected] cd Collaboration-System git pull origin master python3 manage.py collectstatic python3 manage.py migrate sudo supervisorctl restart Collaboration-System exit

Contents

Clone this wiki locally