|
| 1 | +title: How to Provision Ubuntu 18.04 LTS Linux Servers on DigitalOcean |
| 2 | +slug: provision-ubuntu-1804-linux-servers-digitalocean |
| 3 | +meta: Learn how to provision Ubuntu 18.04 LTS on DigitalOcean for deploying your web applications. |
| 4 | +category: post |
| 5 | +date: 2018-10-14 |
| 6 | +modified: 2018-10-14 |
| 7 | +newsletter: False |
| 8 | +headerimage: /img/181014-digitalocean-ubuntu/header.jpg |
| 9 | +headeralt: Flask, Green Unicorn and Ubuntu logos. Copyright their respective owners. |
| 10 | + |
| 11 | + |
| 12 | +[Python web applications](/web-development.html) need to be |
| 13 | +[deployed](/deployment.html) to a production [server](/servers.html) or |
| 14 | +[service](/platform-as-a-service.html) so your users have access to |
| 15 | +the application. |
| 16 | + |
| 17 | +[DigitalOcean](https://do.co/fullstackpython) is one such service |
| 18 | +that makes it easy to immediately get access to initially free servers |
| 19 | +which are low cost (~$5 per month depending on the resources) to continue |
| 20 | +using after the first few months. |
| 21 | + |
| 22 | +In this tutorial we'll learn how to quickly sign up and spin up an |
| 23 | +[Ubuntu](/ubuntu.html)-based Linux server that only you will have |
| 24 | +access to based on a private SSH key. |
| 25 | + |
| 26 | + |
| 27 | +## Obtain Your Virtual Server |
| 28 | +These steps sign you up for a DigitalOcean account and guide you through |
| 29 | +provisioning a virtual private server called a "Droplet" for $5/month which |
| 30 | +we configure throughout the rest of the book. |
| 31 | + |
| 32 | +Point your web browser to |
| 33 | +[Digitalocean.com's registration page](https://do.co/fullstackpython). |
| 34 | +Note that this link uses a referral code which gives you $100 in free |
| 35 | +credit. Feel free to just go to |
| 36 | +[digitalocean.com](https://www.digitalocean.com/) if you |
| 37 | +do not want to use the referral link (you will not get the $100 in credit |
| 38 | +though). Their landing page will look something like the following image. |
| 39 | + |
| 40 | +<img src="/img/181014-digitalocean-ubuntu/do-landing-page.jpg" class="shot rnd outl" alt="DigitalOcean landing page." width="100%"> |
| 41 | + |
| 42 | +Register for a new DigitalOcean account. Fill out the appropriate |
| 43 | +information. When your account is registered and active you can create |
| 44 | +a new DigitalOcean server, which they call "droplets". |
| 45 | + |
| 46 | +After you finish the registration process you will be able to start |
| 47 | +creating DigitalOcean servers. Select the "Create" button which |
| 48 | +opens a drop-down menu. Choose "Droplets" to go to the "Create Droplets" |
| 49 | +page. |
| 50 | + |
| 51 | +<img src="/img/181014-digitalocean-ubuntu/create-droplet.png" class="shot rnd outl" width="100%"> |
| 52 | + |
| 53 | +The new droplet configuration screen will appear and look like |
| 54 | +the following image. The default Ubuntu instance is 16.04, but |
| 55 | +we will use the newer LTS release 18.04 in this book. |
| 56 | + |
| 57 | +<img src="/img/181014-digitalocean-ubuntu/create-droplets-page.jpg" class="shot" width="100%"> |
| 58 | + |
| 59 | +Select the 1 GB memory-sized server for $5 per month. This instance |
| 60 | +size should be perfect for prototypes, side projects and minimum |
| 61 | +viable products. Feel free to choose a larger instance size if you |
| 62 | +want more memory and resources for running your application. |
| 63 | + |
| 64 | +<img src="/img/181014-digitalocean-ubuntu/create-droplet-size.jpg" class="shot" width="100%"> |
| 65 | + |
| 66 | +Scroll down and choose the data center region where you want your |
| 67 | +instance to be located. I typically choose New York because I am |
| 68 | +on the East Coast of the United Statest in Washington, D.C., and you will |
| 69 | +want the server to be closest to your users' location. |
| 70 | + |
| 71 | +<img src="/img/181014-digitalocean-ubuntu/choose-region.png" class="shot" alt="Choose the data center region closest to your customers." width="100%"> |
| 72 | + |
| 73 | +Next, scroll down and click "New SSH Key". Copy and paste in the contents |
| 74 | +of your **public** SSH key. If you do not yet have an SSH key here are a |
| 75 | +couple of guides that will walk you through creating one: |
| 76 | + |
| 77 | +* [Creating SSH keys on macOS](/blog/ssh-keys-macos-sierra.html) |
| 78 | +* [Creating SSH keys on Ubuntu Linux](/blog/ssh-keys-ubuntu-linux.html) |
| 79 | + |
| 80 | +You can see the contents of a public key using the `cat` command. For |
| 81 | +example on my system the command: |
| 82 | + |
| 83 | +```bash |
| 84 | +cat root.pub |
| 85 | +``` |
| 86 | + |
| 87 | +Outputs the contents of my public key: |
| 88 | + |
| 89 | +```bash |
| 90 | +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCqAY/Le17HZpa4+eSoh2L9FMYaQ7EnLOGkYbcbsiQNpnF4FTAemF7tbvMvjpVLU6P9AVGs6qEeJdgTE2gH8fq881AUsQ8it1gla2oAlc+vOZmqWPYaLIl5g9DkGwvbITXayobDcw9wTN5tOITOxp3BV5jqanqoqDAPH1RGfT6A5vkJFsmu4w7cPsn9tiqfZZdge3WkpMNT1M3ou+ogrAwE6Ra531s3zYVG9y1688BGdYzbQFfU0+Pou6Z43Do6xbh2hAfQ5hUuTG0OrE3b/yhGcxEWz0Y9+wPGmxm3/0ioTfMWUG3LOQn+oMtKX/PXX/qOJuUjszbqYBvSYS3kv2IVFGV2KEIKC1xgUDfw+HOV4HlIosIbc97zY83m0Ft+tFavPaiQYrar3wCsVfRUltSR4EwNnLmvNYeMVSS8jSP2ZSPwbL8GO7xxAAS9Oy12set1f4OxdPhEUB9rEfAssU1mE6J5eq+Drs8KX04OasLSLt7kP7wWA27I9pU/y9NRHxEsO0YbLG7DzfHGl4QVXwDjIA5GpwjQMwZLt+lyGc4hpnuXg+IUR6MXI90Hh64ch32nSC8j/hjnWCWgj8Cyuc4Rd/2OtO5dHpbjSyU5Yza2lzIqFbFRo7aQNaIkBIioJnc1d6mrg9mLxfd5Ef2ez9bUjqcq4K7uH/JAm0H2Vk1VFQ== matthew.makai@gmail.com |
| 91 | +``` |
| 92 | + |
| 93 | +Copy and paste this key into the DigitalOcean modal window and give it |
| 94 | +a memorable name for future reference: |
| 95 | + |
| 96 | +<img src="/img/181014-digitalocean-ubuntu/root-key.png" class="shot rnd outl" alt="Paste in the public root key into the modal window." width="100%"> |
| 97 | + |
| 98 | +Optionally, give your server a nickname such as `flask-deploy-manual`. |
| 99 | +Then click the big green "Create" button at the bottom of the screen. |
| 100 | + |
| 101 | +The server provisioning process will begin and our Ubuntu Linux 18.04 |
| 102 | +LTS-powered will soon be ready to go. |
| 103 | + |
| 104 | +Ubuntu 18.04 is the current Long Term Support (LTS) release and has a |
| 105 | +5 year support lifecycle. This version will receive security updates until |
| 106 | +April 2023 as shown on the |
| 107 | +[Ubuntu release end-of-life](https://www.ubuntu.com/info/release-end-of-life) |
| 108 | +page. |
| 109 | + |
| 110 | +<img src="/img/181014-digitalocean-ubuntu/ubuntu-lts-releases.png" class="shot rnd outl" alt="Ubuntu end of life schedule for all releases." width="100%"> |
| 111 | + |
| 112 | +You should now be back on the DigitalOcean dashboard. |
| 113 | + |
| 114 | +<img src="/img/181014-digitalocean-ubuntu/ready-to-deploy.png" class="shot rnd outl" alt="New Ubuntu server ready for access." width="100%"> |
| 115 | + |
| 116 | +Our server is now up and ready for SSH access. |
| 117 | + |
| 118 | +Connect to the server using the IP address associated with it: |
| 119 | + |
| 120 | +``` |
| 121 | +# make sure to replace 192.168.1.1 with your server's IP address |
| 122 | +# and the "private_key" name with the name of your private key |
| 123 | +ssh -i ./private_key 192.168.1.1 |
| 124 | +``` |
| 125 | + |
| 126 | +You should now be connected to your new server and can proceed |
| 127 | +with development or deployment. |
| 128 | + |
| 129 | + |
| 130 | +## What's Next? |
| 131 | +We just stood up a new virtual private server on DigitalOcean that can be |
| 132 | +used as a production or development environment. |
| 133 | + |
| 134 | +Next up I recommend either configuring the development environment or |
| 135 | +deploying your application with one of the following tutorials: |
| 136 | + |
| 137 | +* [Configure Python 3, Flask and Gunicorn on Ubuntu 18.04 LTS](/blog/python-3-flask-gunicorn-ubuntu-1804-bionic-beaver.html) |
| 138 | +* [How to Make Phone Calls in Python](/blog/make-phone-calls-python.html) |
| 139 | +* [5 ways to deploy your Python web app from PyCon US 2017](https://www.youtube.com/watch?v=vGphzPLemZE) |
| 140 | + |
| 141 | +You can also figure out what to code next in your Python project by reading |
| 142 | +the [Full Stack Python table of contents page](/table-of-contents.html). |
| 143 | + |
| 144 | +Questions? Contact me via Twitter |
| 145 | +[@fullstackpython](https://twitter.com/fullstackpython) |
| 146 | +or [@mattmakai](https://twitter.com/mattmakai). I'm also on GitHub with |
| 147 | +the username [mattmakai](https://github.com/mattmakai). |
| 148 | + |
| 149 | +Something wrong with this post? Fork |
| 150 | +[this page's source on GitHub](https://github.com/mattmakai/fullstackpython.com/blob/master/content/posts/181014-digitalocean-ubuntu-1804.markdown) |
| 151 | +and submit a pull request. |
0 commit comments