Skip to content

Running PythonBuddy with Your Own Server

Ethan Chiu edited this page Oct 3, 2017 · 5 revisions

How to Deploy PythonBuddy as your own Server

Based off of https://blog.marksteve.com/deploy-a-flask-application-inside-a-digitalocean-droplet/

Digital Ocean

  1. Create DigitalOcean Droplet with the following features: 14.04 Ubuntu x64 any Size. Choose the closest region

  2. After Droplet is created, ssh into the droplet:

    ssh root@<DROPLET_PUBLIC_IP_ADDRESS>
  3. Add User called deploy:

    useradd -r -m -s /bin/bash deploy
  4. Install pip and easy_install

    apt-get install python-setuptools
    easy_install -U pip
  5. Install virtualenv

    pip install virtualenv
  6. Install git

    apt-get install git
  7. Switch to the deploy user

    su - deploy
  8. Clone PythonBuddy repo and change to that repo

    git clone https://github.com/ethanchewy/OnlinePythonLinterSyntaxChecker
    cd OnlinePythonLinterSyntaxChecker
  9. Make sure you are in the OnlinePythonLinterSyntaxChecker directory and install/activate virualenv

    virtualenv venv
    source venv/bin/activate
  10. Install requirements and gunicorn

    pip install -r requirements.txt
    pip install gunicorn
  11. Press Ctrl-D which will change you to root. Install nginx

    apt-add-repository ppa:nginx/stable
    apt-get update
    apt-get install nginx
  12. Configure nginx to point to gunicorn

    nano /etc/nginx/conf.d/flask-app.conf
  13. Add this to configuration file:

    server {
        listen 80;
    
        server_name _;
    
         access_log  /var/log/nginx/access.log;
         error_log  /var/log/nginx/error.log;
    
        location / {
            proxy_pass         http://127.0.0.1:8000/;
            proxy_redirect     off;
    
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        }
    }
  14. Disable default Nginx Welcome Page

    nano /etc/nginx/nginx.conf
  15. Comment out this line: include /etc/nginx/sites-enabled/; Reload Nginx: service nginx reload

  16. Login back as deploy and load virtualenv

    su - deploy
    cd OnlinePythonLinterSyntaxChecker
    source venv/bin/activate
  17. Run as daemon by default: gunicorn -D app:app

Now Everything Should be working! Just go to your ip address!