-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstallation.qmd
446 lines (343 loc) · 17.5 KB
/
installation.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# Installation Guide
## Assumptions
- This guide assumes the following:
- You are working on a Linux server. We are specifically using Ubuntu 20, but this guide should be consistent for most versions of Linux.
- You have access to the shell command console. You will need access to install files directly onto the server computer.
- You have worked with the command line before.
- You have `sudo` rights to add files and services.
- You know what a hidden file is and at least how to google how to view them.
- You know what SQL and databases are, even if you've never worked with PostgreSQL before.
- You know what Apache and/or nginx servers are and how to edit their files.
- You can at least imagine yourself using git.
## Installation on a Server
### Web Server Installation
- Apache - [Installation Instructions](https://ubuntu.com/tutorials/install-and-configure-apache)
- Nginx - [Installation Instructions](https://ubuntu.com/tutorials/install-and-configure-nginx)
- They really aren't big fans of each other, only install one. We are using nginx on our server.
### Blitz/JS Installation
- Install `node.js` and `npm` - [Installation Instructions](https://www.linode.com/docs/guides/install-nodejs-on-ubuntu-22-04/)
- [Other downloads](https://nodejs.org/en/download)
- You should have at least node v18+ and npm v9+.
- You can check your versions by using `node -v` and `npm -v` in a terminal or command window.
- You may also use yarn, but this guide uses npm.
- Install `blitzjs`: `npm install -g blitz` in a terminal/command window. Check your version is at least v2+ by using `blitz -v` in a command window.
- Depending on server setup, you may need `sudo` privileges.
### Clone This Repository
- Clone or copy this github repository to the server.
- Install git on the machine using: `sudo apt-get update` `sudo apt-get install git`
- Navigate to `/var/www/html/` or `/var/www/` on the Linux machine.
- Clone the repository by using this guide - [Installation Instructions](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository). `git clone https://github.com/STAPLE-verse/STAPLE.git`
- This will make a folder called STAPLE with all the files you need.
- Navigate to that folder by using `cd STAPLE`.
### Database Installation
- Ensure that you have a local postgres service running on your computer.
- To install see: [Installation Instructions](https://www.prisma.io/dataguide/postgresql/setting-up-a-local-postgresql-database).
- Be sure to write down the superuser information as you are installing the setup for non-Linux machines.
- You may use other databases, but will need to modify the provided code for their implementation.
- Create the databases for STAPLE. Go to terminal and use:
- Note that all lines that start with \# are comments for explanation.
```
# get into postgres on linux
sudo -u postgres psql
# enter your password for superuser when prompted
CREATE DATABASE staple;
CREATE DATABASE staple_test;
```
- Create a user with appropriate privileges after postgres installation. While in the terminal and postgres, create a new user:
- Change out `username` and `password` (be sure to leave the quotes!) for your desired user.
```
CREATE USER username WITH PASSWORD 'password';
```
- Get into the STAPLE database. You can use `\l` and should see something like this:
```
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------+----------+----------+-------------+-------------+---------------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
staple | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres +
| | | | | postgres=CTc/postgres +
| | | | | staple=CTc/postgres +
| | | | | staple_admin=CTc/postgres
staple_test | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(5 rows)
```
- Use the following to get into the STAPLE database.
```
postgres=# \c staple
You are now connected to database "staple" as user "postgres".
staple=#
```
- You can check that schema exist using `\dn`:
```
staple=# \dn
List of schemas
Name | Owner
--------+--------
public | staple
(1 row)
staple=#
```
- Give your user the appropriate permissions to write to the database. Change out `username` for the user you created a minute ago.
```
GRANT ALL ON SCHEMA public TO username;
```
- Use `quit;` to exit out of postgres.
### Connect Database to STAPLE App
- Make sure you are in the folder that you copied the github repository into.
- You can use `ls -al` to view all files in that folder.
```
# for example on my server
erin@staple:~$ cd /var/www/html/STAPLE
erin@staple:/var/www/html/STAPLE$ ls -al
total 764
drwxr-xr-x 13 root root 4096 Oct 24 06:17 .
drwxr-xr-x 6 root root 4096 Oct 24 05:02 ..
drwxr-xr-x 3 root root 4096 Oct 24 04:27 db
-rw-r--r-- 1 root root 175 Oct 24 04:27 .editorconfig
-rw-r--r-- 1 root root 494 Oct 24 06:17 .env
# more truncated #
```
- Copy the `.env` file and rename it `.env.local`.
- You may need to turn on settings to see these hidden files on your machine.
- You can create and edit this file at once with `nano .env.local` or `vim` if you want.
- Ensure the `.env.local` file has required environment variables.
- After the commented lines, add the `DATABASE_URL` line and change <YOUR_DB_USERNAME> to `username:password` (no \<\> these are here to show you what to change).
- Create and add a `SESSION_SECRET_KEY`.
- In the command line prompt, use `openssl rand -hex 16` and copy this long letter/number combination instead of <SESSIONKEY>.
```
# This env file should be checked into source control
# This is the place for default values for all environments
# Values in `.env.local` and `.env.production` will override these values
DATABASE_URL=postgresql://<YOUR_DB_USERNAME>@localhost:5432/staple
SESSION_SECRET_KEY=<SESSIONKEY>
```
- Copy the `.env.test` file and rename `.env.test.local`.
- Ensure the `.env.test.local` file has required environment variables in the same way you did above.
```
DATABASE_URL=postgresql://<YOUR_DB_USERNAME>@localhost:5432/staple_test
```
### Install STAPLE Requirements
- Make sure you are in the STAPLE main folder. Use the following (not the `#` line, these are notes) to install packages, tailwind, and daisyui.
```
# to install all packages for staple
npm install
# install tailwind css
blitz install tailwind
# install daisyui
npm i -D daisyui@latest
```
- Next, use the following line to create the database structure/schema for STAPLE to run.
```
# to create database with the right set up
blitz prisma migrate dev
```
### Starting the App - Local Testing
- In a terminal window, go to the folder you cloned this repository and type:
```
blitz dev
```
- Open (usually) <http://localhost:3000> (or whatever it says for localhost in the terminal) with your browser to see the result.
- This step works great on a "regular" computer, but may not be useful for a server. Instead run the service "in production" to view on your website.
### Starting the App - Production
- In a terminal window, go to the folder you cloned this repository and type:
```
blitz build
```
- This step may produce errors in the build. You will need to fix these errors before running the application. Check below for common issues.
### Keeping the App Going
- Create a service.
- Generally, you might consider putting it here: `/etc/systemd/system/` on a linux machine.
- We've named the file `blitz.service` as an example creating it using `nano`.
- Tutorial for those who do not know how to do this - [Installation Instructions](https://www.digitalocean.com/community/tutorials/how-to-configure-a-linux-service-to-start-automatically-after-a-crash-or-reboot-part-1-practical-examples)
```
# for example
erin@staple:/var/www/html/STAPLE$ cd /etc/systemd/system/
erin@staple:/etc/systemd/system$ nano blitz.service
```
- Example file structure:
- Change the `WorkingDirectory` to your folder.
```
[Unit]
Description=Starts the Blitz service.
After=network.target
[Service]
Type=simple
WorkingDirectory=/var/www/html/STAPLE
ExecStart=/usr/local/bin/blitz start
Restart=always
[Install]
WantedBy=default.target
```
- Commands:
- stop: `sudo systemctl stop blitz`
- start: `sudo systemctl start blitz`
- restart: `sudo systemctl restart blitz`
- reload: `sudo systemctl reload blitz`
- disable: `sudo systemctl disable blitz`
- re-enable: `sudo systemctl enable blitz`
- status: `sudo systemctl status blitz`
- reset: `sudo systemctl reset-failed blitz`
*Many thanks to Scott B. for setting this up and giving instructions*.
- Run `sudo systemctl start blitz`.
- Check the status using `sudo systemctl status blitz`. Type the letter `q` to exit.
- Status can also help you troubleshoot when you have an error.
### Setting Up the Proxy
- Use the following to get to the nginx web server: `cd /etc/nginx/sites-enabled`
- Create a file by using `nano YOURWEBSITE` ... for example ours is `nano app.staple.science` because that is the website of our hosted version of STAPLE.
- Create the server file setup:
```
# Default server configuration
#
server {
server_name YOURWEBSITE;
error_log /var/www/html/YOURFOLDER/logs/web-server.log;
location / {
proxy_pass http://localhost:3000/;
}
}
server {
server_name YOURWEBSITE;
listen 80;
}
```
- For `https` you need to set up a certificate and the easiest solution is through `certbot`. See [Installation Instructions](https://certbot.eff.org/).
## Common Errors
## Run on Your Own Computer
You can also run the software locally on your own computer with a few limitations. If you are using a Linux system, you can follow the instructions above from Blitz/JS Installation through Starting the App - Production. You will be the only user allowed to enter data if you use the software on your own computer, as you are not hosting it on the web for others to connect to. However, you can still use all the functionality of project management and metadata entry/output.
### Blitz/JS Installation
- Install `node.js` and `npm` for - [Installation Instructions](https://nodejs.org/en/download)
- This installer includes both `node.js` and `npm`.
- You should have at least node v18+ and npm v9+.
- You can check your versions by using `node -v` and `npm -v` in a terminal or command window.
- You may also use yarn, but this guide uses npm.
- Install `blitzjs`: `npm install -g blitz` in a terminal/command window. Check your version is at least v2+ by using `blitz -v` in a command window.
- Depending on your computer setup, you may need `sudo` privileges.
### Clone This Repository
- Clone or copy this github repository to your computer - [Installation Instructions](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository). `git clone https://github.com/STAPLE-verse/STAPLE.git`
- This will make a folder called STAPLE with all the files you need.
- Navigate to that folder in your terminal window.
### Database Installation
- Ensure that you have a local postgres service running on your computer.
- To install see: [Installation Instructions](https://www.prisma.io/dataguide/postgresql/setting-up-a-local-postgresql-database).
- Be sure to write down the superuser information as you are installing the setup for non-Linux machines.
- You may use other databases, but will need to modify the provided code for their implementation.
- Create the databases for STAPLE. Go to terminal and use:
- Note that all lines that start with \# are comments for explanation.
```
# get into postgres on mac
psql -U postgres
# enter your password for superuser when prompted
CREATE DATABASE staple;
CREATE DATABASE staple_test;
```
- Create a user with appropriate privileges after postgres installation. While in the terminal and postgres, create a new user:
- Change out `username` and `password` (be sure to leave the quotes!) for your desired user.
```
CREATE USER username WITH PASSWORD 'password';
```
- Get into the STAPLE database. You can use `\l` and should see something like this:
```
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------+----------+----------+-------------+-------------+---------------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
staple | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres +
| | | | | postgres=CTc/postgres +
| | | | | staple=CTc/postgres +
| | | | | staple_admin=CTc/postgres
staple_test | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(5 rows)
```
- Use the following to get into the STAPLE database.
```
postgres=# \c staple
You are now connected to database "staple" as user "postgres".
staple=#
```
- You can check that schema exist using `\dn`:
```
staple=# \dn
List of schemas
Name | Owner
--------+--------
public | staple
(1 row)
staple=#
```
- Give your user the appropriate permissions to write to the database. Change out `username` for the user you created a minute ago.
```
GRANT ALL ON SCHEMA public TO username;
```
- Use `quit;` to exit out of postgres.
### Connect Database to STAPLE App
- Make sure you are in the folder that you copied the github repository into.
- You can use `ls -al` to view all files in that folder.
```
# for example on my server
erin@staple:~$ cd /var/www/html/STAPLE
erin@staple:/var/www/html/STAPLE$ ls -al
total 764
drwxr-xr-x 13 root root 4096 Oct 24 06:17 .
drwxr-xr-x 6 root root 4096 Oct 24 05:02 ..
drwxr-xr-x 3 root root 4096 Oct 24 04:27 db
-rw-r--r-- 1 root root 175 Oct 24 04:27 .editorconfig
-rw-r--r-- 1 root root 494 Oct 24 06:17 .env
# more truncated #
```
- Copy the `.env` file and rename it `.env.local`.
- You may need to turn on settings to see these hidden files on your machine.
- You can create and edit this file at once with `nano .env.local` or `vim` if you want.
- Ensure the `.env.local` file has required environment variables.
- After the commented lines, add the `DATABASE_URL` line and change <YOUR_DB_USERNAME> to `username:password` (no \<\> these are here to show you what to change).
- Create and add a `SESSION_SECRET_KEY`.
- In the command line prompt, use `openssl rand -hex 16` and copy this long letter/number combination instead of <SESSIONKEY>.
```
# This env file should be checked into source control
# This is the place for default values for all environments
# Values in `.env.local` and `.env.production` will override these values
DATABASE_URL=postgresql://<YOUR_DB_USERNAME>@localhost:5432/staple
SESSION_SECRET_KEY=<SESSIONKEY>
```
- Copy the `.env.test` file and rename `.env.test.local`.
- Ensure the `.env.test.local` file has required environment variables in the same way you did above.
```
DATABASE_URL=postgresql://<YOUR_DB_USERNAME>@localhost:5432/staple_test
```
### Install STAPLE Requirements
- Make sure you are in the STAPLE main folder. Use the following (not the `#` line, these are notes) to install packages, tailwind, and daisyui.
```
# to install all packages for staple
npm install
# install tailwind css
blitz install tailwind
# install daisyui
npm i -D daisyui@latest
```
- Next, use the following line to create the database structure/schema for STAPLE to run.
```
# to create database with the right set up
blitz prisma migrate dev
```
### Starting the App - Local Testing
- In a terminal window, go to the folder you cloned this repository and type:
```
blitz dev
```
- Open (usually) <http://localhost:3000> (or whatever it says for localhost in the terminal) with your browser to see the result.
- Everything you do will be saved this way, so closing the app would mean just closing the app.
### Starting the App - Production
- In a terminal window, go to the folder you cloned this repository and type:
```
blitz build
```
- This step may produce errors in the build. You will need to fix these errors before running the application. Check below for common issues.