Skip to content

Commit a24d4f6

Browse files
authored
Merge pull request #39 from LUS24/master
2 parents c9e20dd + 1d7c28f commit a24d4f6

File tree

3 files changed

+37
-90
lines changed

3 files changed

+37
-90
lines changed

guides/DigitalOcean Tutorial.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,55 @@ DigitalOcean is a cloud infrastructure provider focused on simplifying web infra
66

77
## Creating an account
88

9-
You can sign up to DigitalOcean using our affiliate link. Doing so gives you a starting credit of $10, which allows you to rent a server for 2 months. Click this link to create your account and get the $10: [https://m.do.co/c/d54c088544ed](https://m.do.co/c/d54c088544ed). If the link doesn't work, paste it into your browser.
9+
You can sign up to DigitalOcean using our affiliate link. Doing so gives you a starting credit of $100 to spend in 60 days. Click this link to create your account and get the $100: [https://m.do.co/c/d54c088544ed](https://m.do.co/c/d54c088544ed). If the link doesn't work, paste it into your browser.
1010

1111
![Create an account](assets/DigitalOcean/create_account.png)
1212

13-
After clicking the link, you should see a page like the above. Create your account at the left-bottom corner and you'll receive the $10 automatically. Beware that you'll be asked to provide payment info when creating the account, since all services (which you'll choose below) in DigitalOcean will be charged after your credit runs out.
13+
After clicking the link, you should see a page like the above. Create your account at the left-bottom corner and you'll receive the $100 automatically. Beware that you'll be asked to provide payment info when creating the account, since all services (which you'll choose below) in DigitalOcean will be charged after your credit runs out.
1414

1515
## Creating a Droplet
1616

1717
A server instance in DigitalOcean is called a `Droplet`. It's just a name that may vary in different platforms, for example, `Dyno` for `Heroku` and `EC2` for `AWS` (Amazon Web Service). Below are the steps to create a `Droplet`.
1818

1919
### Choosing an image
2020

21-
To create a `Droplet`, we must first specify an image, that is, choosing what Operating System you want for the server. We recommend to use a Ubuntu LTS (Long Term Support) distribution. For more info on Ubuntu life time, please refer to the [official Ubuntu end of life page here](https://www.ubuntu.com/info/release-end-of-life). In our example, we'll use `Ubuntu 16.04.* x64`, which is an LTS distribution.
21+
To create a `Droplet`, we must first specify an image, that is, choosing what Operating System you want for the server. We recommend to use a Ubuntu LTS (Long Term Support) distribution. For more info on Ubuntu life time, please refer to the [official Ubuntu end of life page here](https://www.ubuntu.com/info/release-end-of-life). In our example, we'll use `Ubuntu 20.04 (LTS) x64`, which is an LTS distribution.
2222

2323
### Choosing a size
2424

25-
Next, we need to choose the specs for our server. In this tutorial, we'll be using the most basic tier of a Standard `Droplet`, which offers a single CPU with 512MB RAM, 20GB SSD and 1000 GB transfer at $5 per month. Generally, it's more than enough for running personal applications. You may also run several services in a single Droplet.
25+
Next, we need to choose the specs for our server. In this tutorial, we'll be using the most basic tier of a Standard `Droplet`, which offers a single Regular Intel CPU with 1GB RAM, 25GB SSD and 1000 GB transfer at $5 per month. Generally, it's more than enough for running personal applications. You may also run several services in a single Droplet.
2626

2727
### Choosing a datacenter region
2828

2929
Generally, choosing a region that's _closest to your users_ will make your service deliver faster. If your users are primarily in the United States, you could choose a United States-based Droplet.
3030

3131
### Other configurations
3232

33-
In our example, we do not need to add any other services such as block storage or private network. So we will ignore these settings to keep our setup simple and cheap. You may choose to use `SSH` key or you can just leave it unchecked and a password will be generated for you. If you choose to use SSH key, then each time you want to login to the server, you will need to provide the key. Since you have to have access to the SSH key whenever you log in, it can be more secure or more troublesome depends on scenarios. At last, you may change the name of your `Droplet` to something you like and then click `Create` to create and launch your `Droplet`.
33+
In our example, we do not need to add any other services such as block storage or private network. So we will ignore these settings to keep our setup simple and cheap.
34+
You may choose to use `SSH` key and follow the steps recommended by DigitalOcean or create a password.
3435

35-
## Connecting to our droplet
36+
#### Setting up a password
3637

37-
![DigitalOcean Access Console](assets/DigitalOcean/access_console.png)
38+
If you want to use a password you just have to select the __"Create a root password to access Droplet"__ and then insert a strong password which you can use to login remotely or through DigitalOcean's Droplet Console.
39+
40+
#### Setting up an SSH key
41+
42+
If you choose to use SSH key, then each time you want to login to the server from outside DigitalOcean's site, you will need to provide the key. For example in windows using [GitBash terminal](https://git-scm.com/downloads) you need to add the `-i` option and pass the full path for the ssh-key file:
43+
44+
```bash
45+
ssh root@insert-droplet-ip -i /c/Users/insert-username/.ssh/insert-ssh-key-filename
46+
```
3847

39-
Once you've created your `Droplet`, you will receive an e-mail containing your login (`root`) and initial password for it. Now click the "Access Console" option in the dropdown menu associated with your `Droplet` as shown in above image.
48+
Be aware that this command will only work for the root user, if you want to add an ssh key for another user you can see the details in [DigitalOcean's docs](https://docs.digitalocean.com/products/droplets/how-to/add-ssh-keys/).
4049

41-
## Change your password
50+
Since you have to have access to the SSH key whenever you log in, it can be more secure or more troublesome depending on the scenario.
51+
At last, you may change the name of your `Droplet` to something you like and then click `Create` to create and launch your `Droplet`.
52+
53+
## Connecting to our droplet
54+
55+
![DigitalOcean Access Console](assets/DigitalOcean/access_console.png)
4256

43-
Now you will be shown a console connected to your `Droplet`. Use the login `root` and the password received in your email to login. Then you will be ask to provide your password again and change it to a new password. Notice that all password field will not show any modification when you are typing. There is nothing wrong with your console, it's just a `UNIX` security feature. After changing your password, you are now logged in as the root user on your server.
57+
Once you've created your `Droplet` click the "Access Console" option in the dropdown menu associated with your `Droplet`, as shown in above image, and click the `Launch Droplet Console` button.
4458

4559
If you have successfully followed the tutorial so far, then you have finished all the setting-ups that are specific to DigitalOcean. The following sections can serve as a standalone tutorial and can be applied to deployment onto any other platforms as well.
4660

guides/How To Deploy Python App Using uWSGI And Nginx.md

Lines changed: 13 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -62,85 +62,12 @@ passwd johndoe
6262

6363
## Providing user with additional privilege
6464

65-
Since we will be logging in as `johndoe` for most of the time in the future, we will want it to have some "extra power", that is, temporarily acting as a super user. To do this, we need to run the command:
65+
Since we will be logging in as `johndoe` for most of the time in the future, we will want it to have some "extra power", that is, temporarily acting as a super user. To do this, we have to add the user to the sudoers group running the command:
6666

6767
```
68-
visudo
68+
usermod -aG sudo johndoe
6969
```
7070

71-
first, and we will see a text file popping up. Then we navigate to the lines containing:
72-
73-
```
74-
# User privilege specification
75-
root ALL=(ALL:ALL) ALL
76-
```
77-
78-
You can do this with the arrow keys. We need to add a new line for our user in this section:
79-
80-
```
81-
# User privilege specification
82-
root ALL=(ALL:ALL) ALL
83-
johndoe ALL=(ALL:ALL) ALL
84-
```
85-
86-
Remember that the `ALL` has to be **all uppercase**, otherwise it will raise syntax error.
87-
88-
After adding this line, use `ctrl + o` to save and press `ENTER` to overwrite, then press `ctrl + x` to quit.
89-
90-
## Enable SSH for our new user
91-
92-
Next, we want to allow us to login as `johndoe` using SSH, and we may also want to disable login as `root` from SSH to make our server more secure. To do this, use the command:
93-
94-
```
95-
vi /etc/ssh/sshd_config
96-
```
97-
98-
And we will be prompted with another text file. Navigate to the section which contains:
99-
100-
```
101-
# Authentication
102-
PermitRootLogin yes
103-
```
104-
105-
Press `i` on your keyboard to enter insert mode and change the `yes` to `no` to disallow login as root.
106-
107-
Next, look for a configuration called `PasswordAuthentication`:
108-
109-
```
110-
# Change to no to disable tunnelled clear text passwords
111-
PasswordAuthentication yes
112-
```
113-
114-
**Important:** make sure to set it as `yes` so that you can use your password to login in the future. It should be set to `yes` already, however, there are some platforms that enforces SSH key authentication and set it to `no` instead.
115-
116-
Then go to the bottom of the file and add the following lines:
117-
118-
```
119-
AllowUsers johndoe
120-
```
121-
122-
For this section, if you already have other users on the server, make sure to include them as well. On AWS, for instance, a user named `ubuntu` is initialized and used to login for the first time. If you choose to create a new user, say `johndoe`, then you will need to add them together into `AllowUsers`:
123-
124-
```
125-
AllowUsers johndoe ubuntu
126-
```
127-
128-
Otherwise, you will no longer be able to login as `ubuntu` in the future.
129-
130-
Next, press `Esc` to quit insert mode, press `:` (colon) to enable the command function and enter `wq` to write and quit (after hitting `ENTER` to confirm).
131-
132-
Some other useful vi commands are: `:q` to quit without modification and `:q!` to force quit and discard changes.
133-
134-
Finally, we use the command:
135-
136-
```
137-
service sshd reload
138-
```
139-
140-
to enable our modifications.
141-
142-
Now we've created a new user `johndoe` and enabled both its super user privilege and SSH access. Next, we'll be learning to link this user to our PostgreSQL database.
143-
14471
# Configuring Postgres
14572

14673
Postgres allows from the start a user to access a database with its own name. Thus we must:
@@ -195,12 +122,18 @@ To quit Postgres:
195122
\q
196123
```
197124

125+
Change to user johndoe
126+
127+
```
128+
su johndoe
129+
```
130+
198131
## Improve security on our PostgreSQL database
199132

200133
However, notice that we've created a password for the Postgres user but never have to use it just because we used the same username in UNIX and Postgres. It is safer to require a password when connecting to the database. Use the below command to configure Postgres security options.
201134

202135
```
203-
sudo vi /etc/postgresql/9.5/main/pg_hba.conf
136+
sudo vi /etc/postgresql/12/main/pg_hba.conf
204137
```
205138

206139
Navigate to the bottom of the file, and we may see something like this:
@@ -244,7 +177,7 @@ In this section, we will pull our code from `GitHub`, which integrates a popular
244177
First, we create a folder called `items-rest` for our app, since our sample project is a REST API which manages items of stores. We create this folder using the following command:
245178

246179
```
247-
sudo mkdir /var/www/html/items-rest
180+
sudo mkdir -p /var/www/html/items-rest
248181
```
249182

250183
The folder is owned by the `root` user since we used `sudo` to create it. We need to transfer ownership to our current user:
@@ -279,16 +212,16 @@ sudo apt-get install python3-pip python3-dev libpq-dev
279212
Next, we will install `virtualenv`, which is a python library used to create virtual environment. Since we may want to deploy several services on one server in the future, using virtual environment allows us to create independent environment for each project so that their dependencies won't affect each other. We may install `virtualenv` using the following command:
280213

281214
```
282-
pip install virtualenv
215+
sudo pip install virtualenv
283216
```
284217

285218
After it is installed, we can create a `virtualenv`:
286219

287220
```
288-
virtualenv venv --python=python3.8.5
221+
virtualenv venv --python=python3.8
289222
```
290223

291-
Note that `Ubuntu` usually comes with `Python3.8.5` and it is what we used in the sample code, if you choose to use different versions of `Python`, feel free to change it accordingly and it will be the Python version inside your `virtualenv`.
224+
Note that `Ubuntu 20.04` usually comes with `Python3.8` and it is what we used in the sample code, if you choose to use different versions of `Python`, feel free to change it accordingly and it will be the Python version inside your `virtualenv`.
292225

293226
To activate `virtualenv`:
294227

879 Bytes
Loading

0 commit comments

Comments
 (0)