Skip to content

Commit 05b4fe6

Browse files
Description for self-hosting configuration in README.md.
1 parent 749eb21 commit 05b4fe6

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed

README.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,150 @@ If you are unable to use Docker, please contact a core team member to get instru
204204

205205
</details>
206206

207+
<details>
208+
<summary>Instructions for self-hosting LiteFarm</summary>
209+
210+
### Self-hosting LiteFarm
211+
212+
To self-host LiteFarm, you will need to:
213+
214+
1. Configure domain.
215+
2. Configure Linux server.
216+
3. Set up a web server (e.g. Nginx or Apache).
217+
4. Set up a [Postgres database](#database-setup).
218+
5. Set up services.
219+
6. LiteFarm configuration.
220+
7. Compile and startup LiteFarm.
221+
222+
#### Domain
223+
224+
LiteFarm uses few endpoints and each endpoint needs its own domain:
225+
226+
- main address like `yourdomain.com` where the webapp is hosted,
227+
- api address like `api.yourdomain.com` where the api is hosted,
228+
- file service address like `files.yourdomain.com`.
229+
230+
All domain should be pointed to the server IP address on which each service is hosted.
231+
If all services are hosted on the same server then it will be the same IP address.
232+
233+
#### Linux server
234+
235+
LiteFarm can be hosted on any server that supports Node.js, PostgreSQL or Docker. Recommended is Ubuntu or Debian
236+
but any Linux distribution should work.
237+
238+
There are few possibilities to self-host LiteFarm:
239+
240+
- from scratch on a server,
241+
- using Docker.
242+
243+
Node.js should be in version pointed in `.nvmrc` file in the root of the repo.
244+
Using [NVM](https://github.com/nvm-sh/nvm) is recommended.
245+
246+
Other recommendations:
247+
248+
- install/start LiteFarm `api` service as non-root user,
249+
- configure firewall to allow only necessary ports,
250+
- use SSL certificates for secure connections.
251+
252+
When installing from scratch, you will need to install Node.js, PostgreSQL, Redis and other dependencies manually.
253+
254+
#### Web server
255+
256+
LiteFarm is built with Node.js and can be run directly on the server.
257+
However, it is recommended to use a web server like Nginx or Apache to
258+
handle incoming requests and route them to the appropriate service.
259+
260+
Using Nginx or Apache will also allow you to use SSL certificates for secure connections.
261+
262+
Nginx or Apache will be also needed if all services are hosted on the same server.
263+
264+
#### Postgres
265+
266+
Database can be used from [Docker container](#postgresql-database)
267+
or [installed directly](#database---native-installation) on the server.
268+
269+
#### LiteFarm services
270+
271+
LiteFarm uses few services to handle images, documents and certification exports.
272+
This can be done using Docker containers or installed directly on the server
273+
as [described above](#services-local-development-dependencies).
274+
275+
#### LiteFarm configuration
276+
277+
When we have all services running, we need to configure packages LiteFarm to use them.
278+
279+
1. Api service `packages/api/.env`:
280+
281+
```ini
282+
# Set correct NODE_ENV
283+
NODE_ENV=production
284+
PORT=5001
285+
# Public API URL
286+
API_PUBLIC_URL=https://api.yourdomain.com
287+
# Webapp public URL
288+
HOME_PUBLIC_URL=https://youdomain.com
289+
290+
# S3 storage configuration
291+
S3_ENDPOINT=??
292+
S3_ENDPOINT_BUCKET=??
293+
S3_PUBLIC_BUCKET_NAME=??
294+
S3_PRIVATE_BUCKET_NAME=???
295+
S3_REGION=???
296+
S3_ACCESS_KEY_ID=???
297+
S3_SECRET_ACCESS_KEY=???
298+
#S3_FORCE_PATH_STYLE=true/false
299+
300+
# Email configuration (SMTP)
301+
#EMAIL_TRANSPORT_HOST=smtp.server.com
302+
#EMAIL_TRANSPORT_PORT=465
303+
#EMAIL_TRANSPORT_SECURE=true
304+
#EMAIL_TRANSPORT_SERVICE=smtp
305+
#EMAIL_TRANSPORT_USER=?
306+
#EMAIL_TRANSPORT_PASSWORD=?
307+
```
308+
309+
Other variables should be set as in `.env.default` file.
310+
311+
2. File service `packages/fileservice/.env`. Just use `packages/fileservice/.env.default` file as a template
312+
and set the same values for `S3_*` variables as in `packages/api/.env` (you can omit the `PUBLIC` bucket settings)
313+
and `JWT_FARM_SECRET` which should be the same as in `packages/api/.env`.
314+
3. Webapp `packages/webapp/.env`:
315+
```ini
316+
VITE_API_URL=https://api.yourdomain.com
317+
VITE_S3_SERVICE=https://files.yourdomain.com
318+
```
319+
Other variables should be set as in `.env.default` file.
320+
321+
#### Compile and startup LiteFarm
322+
323+
Each endpoint should be compiled and started separately.
324+
325+
1. Webapp:
326+
```bash
327+
cd packages/webapp
328+
pnpm build
329+
```
330+
Now you can copy the `dist` folder to the web server root directory and configure the web server to serve it
331+
(static files) or point the web server to the `dist` folder or use `serve` command to serve the files
332+
and configure the web server to proxy the requests to the `serve` command/port.
333+
2. File service:
334+
```bash
335+
cd packages/fileservice
336+
npm run start
337+
```
338+
3. Api:
339+
```bash
340+
cd packages/api
341+
npm run build
342+
npm run start:prod
343+
```
344+
You need to keep in mind two things:
345+
346+
- all [preliminaries](#preliminaries) should be done before running the commands above,
347+
- all [services](#services-local-development-dependencies) should be running before starting the api.
348+
349+
</details>
350+
207351
# Testing
208352

209353
## api

0 commit comments

Comments
 (0)