lnbits/docs/guide/installation.md

155 lines
5.1 KiB
Markdown
Raw Normal View History

---
layout: default
title: Basic installation
nav_order: 2
---
2021-07-07 09:58:21 +00:00
# Basic installation
2021-11-12 11:38:07 +00:00
Install Postgres and setup a database for LNbits:
2022-01-27 20:07:47 +00:00
2021-11-12 11:38:07 +00:00
```sh
# on debian/ubuntu 'sudo apt-get -y install postgresql'
# or follow instructions at https://www.postgresql.org/download/linux/
# Postgres doesn't have a default password, so we'll create one.
2021-11-12 11:44:44 +00:00
sudo -i -u postgres
psql
2021-11-12 11:38:07 +00:00
# on psql
ALTER USER postgres PASSWORD 'myPassword'; # choose whatever password you want
\q
2021-11-12 11:44:44 +00:00
# on postgres user
createdb lnbits
2021-11-12 11:38:07 +00:00
exit
```
Download this repo and install the dependencies:
```sh
2021-11-08 09:50:11 +00:00
git clone https://github.com/lnbits/lnbits-legend.git
2022-01-14 09:17:07 +00:00
cd lnbits-legend/
2021-05-22 23:35:37 +00:00
# ensure you have virtualenv installed, on debian/ubuntu 'apt install python3-venv' should work
2020-10-02 17:53:55 +00:00
python3 -m venv venv
./venv/bin/pip install -r requirements.txt
cp .env.example .env
2021-11-12 11:38:07 +00:00
# add the database connection string to .env 'nano .env' LNBITS_DATABASE_URL=
2022-01-14 09:20:20 +00:00
# postgres://<user>:<myPassword>@<host>/<lnbits> - alter line bellow with your user, password and db name
2021-11-12 11:38:07 +00:00
LNBITS_DATABASE_URL="postgres://postgres:postgres@localhost/lnbits"
# save and exit
2021-11-04 15:21:17 +00:00
./venv/bin/uvicorn lnbits.__main__:app --port 5000
```
2021-11-04 15:21:17 +00:00
Now you can visit your LNbits at http://localhost:5000/.
2020-10-02 17:53:55 +00:00
Now modify the `.env` file with any settings you prefer and add a proper [funding source](./wallets.md) by modifying the value of `LNBITS_BACKEND_WALLET_CLASS` and providing the extra information and credentials related to the chosen funding source.
Then you can restart it and it will be using the new settings.
2020-10-16 02:12:32 +00:00
You might also need to install additional packages or perform additional setup steps, depending on the chosen backend. See [the short guide](./wallets.md) on each different funding source.
2021-11-12 11:38:07 +00:00
## Important note
If you already have LNbits installed and running, on an SQLite database, we **HIGHLY** recommend you migrate to postgres!
There's a script included that can do the migration easy. You should have Postgres already installed and there should be a password for the user, check the guide above. Additionally, your lnbits instance should run once on postgres to implement the database schema before the migration works:
2022-01-27 20:07:47 +00:00
```sh
# STOP LNbits
# add the database connection string to .env 'nano .env' LNBITS_DATABASE_URL=
# postgres://<user>:<password>@<host>/<database> - alter line bellow with your user, password and db name
LNBITS_DATABASE_URL="postgres://postgres:postgres@localhost/lnbits"
# save and exit
# START LNbits
# STOP LNbits
# on the LNBits folder, locate and edit 'conv.py' with the relevant credentials
python3 conv.py
```
Hopefully, everything works and get migrated... Launch LNbits again and check if everything is working properly.
2021-11-12 11:38:07 +00:00
2021-07-07 09:58:21 +00:00
# Additional guides
2022-01-27 20:07:47 +00:00
### LNbits as a systemd service
Systemd is great for taking care of your LNbits instance. It will start it on boot and restart it in case it crashes. If you want to run LNbits as a systemd service on your Debian/Ubuntu/Raspbian server, create a file at `/etc/systemd/system/lnbits.service` with the following content:
```
# Systemd unit for lnbits
# /etc/systemd/system/lnbits.service
[Unit]
Description=LNbits
2022-06-01 11:25:37 +00:00
# you can uncomment these lines if you know what you're doing
# it will make sure that lnbits starts after lnd (replace with your own backend service)
#Wants=lnd.service
#After=lnd.service
2022-01-27 20:07:47 +00:00
[Service]
2022-06-01 11:25:37 +00:00
# replace with the absolute path of your lnbits installation
WorkingDirectory=/home/bitcoin/lnbits
# same here
ExecStart=/home/bitcoin/lnbits/venv/bin/uvicorn lnbits.__main__:app --port 5000
# replace with the user that you're running lnbits on
User=bitcoin
2022-01-27 20:07:47 +00:00
Restart=always
TimeoutSec=120
RestartSec=30
2022-06-01 11:25:37 +00:00
# this makes sure that you receive logs in real time
Environment=PYTHONUNBUFFERED=1
2022-01-27 20:07:47 +00:00
[Install]
WantedBy=multi-user.target
```
Save the file and run the following commands:
```sh
sudo systemctl enable lnbits.service
sudo systemctl start lnbits.service
```
2021-07-07 09:58:21 +00:00
### LNbits running on Umbrel behind Tor
If you want to run LNbits on your Umbrel but want it to be reached through clearnet, _Uxellodunum_ made an extensive [guide](https://community.getumbrel.com/t/guide-lnbits-without-tor/604) on how to do it.
### Docker installation
To install using docker you first need to build the docker image as:
2021-07-07 09:58:21 +00:00
```
git clone https://github.com/lnbits/lnbits.git
cd lnbits/ # ${PWD} referred as <lnbits_repo>
docker build -t lnbits .
```
You can launch the docker in a different directory, but make sure to copy `.env.example` from lnbits there
2021-07-07 09:58:21 +00:00
```
cp <lnbits_repo>/.env.example .env
```
2021-07-07 09:58:21 +00:00
and change the configuration in `.env` as required.
Then create the data directory for the user ID 1000, which is the user that runs the lnbits within the docker container.
2021-07-07 09:58:21 +00:00
```
mkdir data
sudo chown 1000:1000 ./data/
```
Then the image can be run as:
2021-07-07 09:58:21 +00:00
```
docker run --detach --publish 5000:5000 --name lnbits --volume ${PWD}/.env:/app/.env --volume ${PWD}/data/:/app/data lnbits
2021-06-19 01:41:30 +00:00
```
2021-07-07 09:58:21 +00:00
Finally you can access your lnbits on your machine at port 5000.
2021-07-07 09:57:45 +00:00
2021-07-07 09:58:21 +00:00
# Additional guides
2021-07-07 09:57:45 +00:00
## LNbits running on Umbrel behind Tor
If you want to run LNbits on your Umbrel but want it to be reached through clearnet, _Uxellodunum_ made an extensive [guide](https://community.getumbrel.com/t/guide-lnbits-without-tor/604) on how to do it.