You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/DigitalOcean Tutorial.md
+24-10Lines changed: 24 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -6,41 +6,55 @@ DigitalOcean is a cloud infrastructure provider focused on simplifying web infra
6
6
7
7
## Creating an account
8
8
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.
10
10
11
11

12
12
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.
14
14
15
15
## Creating a Droplet
16
16
17
17
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`.
18
18
19
19
### Choosing an image
20
20
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.
22
22
23
23
### Choosing a size
24
24
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.
26
26
27
27
### Choosing a datacenter region
28
28
29
29
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.
30
30
31
31
### Other configurations
32
32
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.
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:
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/).
40
49
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`.
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.
44
58
45
59
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.
Copy file name to clipboardExpand all lines: guides/How To Deploy Python App Using uWSGI And Nginx.md
+13-80Lines changed: 13 additions & 80 deletions
Original file line number
Diff line number
Diff line change
@@ -62,85 +62,12 @@ passwd johndoe
62
62
63
63
## Providing user with additional privilege
64
64
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:
66
66
67
67
```
68
-
visudo
68
+
usermod -aG sudo johndoe
69
69
```
70
70
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
-
144
71
# Configuring Postgres
145
72
146
73
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:
195
122
\q
196
123
```
197
124
125
+
Change to user johndoe
126
+
127
+
```
128
+
su johndoe
129
+
```
130
+
198
131
## Improve security on our PostgreSQL database
199
132
200
133
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.
201
134
202
135
```
203
-
sudo vi /etc/postgresql/9.5/main/pg_hba.conf
136
+
sudo vi /etc/postgresql/12/main/pg_hba.conf
204
137
```
205
138
206
139
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
244
177
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:
245
178
246
179
```
247
-
sudo mkdir /var/www/html/items-rest
180
+
sudo mkdir -p /var/www/html/items-rest
248
181
```
249
182
250
183
The folder is owned by the `root` user since we used `sudo` to create it. We need to transfer ownership to our current user:
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:
280
213
281
214
```
282
-
pip install virtualenv
215
+
sudo pip install virtualenv
283
216
```
284
217
285
218
After it is installed, we can create a `virtualenv`:
286
219
287
220
```
288
-
virtualenv venv --python=python3.8.5
221
+
virtualenv venv --python=python3.8
289
222
```
290
223
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`.
0 commit comments