Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Digital Ocean

Plan

  • Introduction to Digital Ocean
  • Setup local environment for Web development and testing.
  • Create a Digital Ocean Droplet = Virtual Private Server (VPS).
  • Set up Python on the droplet.
  • Set up Nginx web server on droplet.

What is Digital Ocean?

Register on Digital Ocean

Local installations

Web Application Development Environment

  • Web application with templates, accepting parameters (echo), tests
  • Project in GitHub: Python Flask Demo
  • Download as a zip file or clone locally
  • Install the requirements locally
  • Run the application locally

Create ssh keypair

  • Generate ssh keypair by running git-keygen
ssh-keygen.exe
ls -l ~/.ssh

Create a Droplet

  • In order to add the ssh key to Digital Ocean run this:
cat ~/.ssh/id_rsa.pub
  • And copy the content

ssh to the Droplet

ssh root@IP
  • Accept the ECDSA fingerprint by typing "yes"
upime

Update packages

apt-get update
apt-get dist-upgrade
reboot

Install nginx

  • Try to visit: http://IP
apt-get install nginx
  • Try to visit: http://IP

  • Edit /var/www/html/index.nginx-debian.html and see the changes are reflected on the web page.

Install python3

which python3
apt-get install python3
apt-get install virtualenv

Create user to have the application

adduser --gecos '' --disabled-password  dev

Add the application source code

Switch to the user:

su - dev
  • By cloning:
git clone https://github.com/szabgab/python-flask-demo.git
cd python-flask-demo
virtualenv -p python3 venv3
  • By upload using scp, run the command on your desktop:
scp -r README.md root@IP:

This is just an example, you need to zip the files on your computer, scp the zip file and unzip in user dev.

Configure nginx

ls -l /etc/nginx/sites-enabled/
rm /etc/nginx/sites-enabled/default
ln -s /home/dev/python-flask-demo/config/demo-nginx.conf /etc/nginx/sites-enabled/demo-nginx.conf

If there are problems you can take a look at this file:

/var/log/nginx/python-flask-demo.error.log

Install and configure uwsgi

apt-get install uwsgi
apt-get install uwsgi-plugin-python3
ln -s /home/dev/python-flask-demo/config/demo-uwsgi.ini /etc/uwsgi/apps-enabled/demo-uwsgi.ini
service uwsgi restart

If there is a problem you might find help by looking at the log file:

/var/log/uwsgi/app/demo-uwsgi.log