2020-09-03 19:53:22 +02:00
---
layout: default
title: Basic installation
nav_order: 2
---
2021-07-07 11:58:21 +02:00
# Basic installation
2022-07-13 01:15:48 +02:00
2022-07-28 12:19:30 +02:00
You can choose between four package managers, `poetry` , `nix` and `venv` .
2022-07-13 01:15:48 +02:00
By default, LNbits will use SQLite as its database. You can also use PostgreSQL which is recommended for applications with a high load (see guide below).
2022-07-27 16:01:23 +02:00
## Option 1: poetry
2022-07-13 01:15:48 +02:00
2022-07-27 16:01:23 +02:00
```sh
git clone https://github.com/lnbits/lnbits-legend.git
cd lnbits-legend/
2022-08-02 23:02:53 +02:00
# for making sure python 3.9 is installed, skip if installed
2022-08-02 22:59:55 +02:00
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.9
2022-07-27 16:01:23 +02:00
curl -sSL https://install.python-poetry.org | python3 -
2022-08-02 22:59:55 +02:00
export PATH="/home/ubuntu/.local/bin:$PATH" # or whatever is suggested in the poetry install notes printed to terminal
2022-08-02 22:01:58 +02:00
poetry env use python3.9
2022-07-27 16:01:23 +02:00
poetry install
2022-08-02 22:59:55 +02:00
mkdir data
2022-08-02 23:00:55 +02:00
cp .env.example .env
2022-08-02 23:01:09 +02:00
sudo nano .env # set funding source
2022-08-02 22:59:55 +02:00
2022-07-27 16:01:23 +02:00
```
#### Running the server
```sh
poetry run lnbits
# To change port/host pass 'poetry run lnbits --port 9000 --host 0.0.0.0'
```
2022-07-28 12:19:30 +02:00
## Option 2: Nix
2022-07-13 01:15:48 +02:00
```sh
git clone https://github.com/lnbits/lnbits-legend.git
cd lnbits-legend/
2022-07-28 12:19:30 +02:00
# Modern debian distros usually include Nix, however you can install with:
# 'sh <(curl -L https://nixos.org/nix/install) --daemon', or use setup here https://nixos.org/download.html#nix-verify-installation
2022-07-13 01:15:48 +02:00
2022-07-28 12:19:30 +02:00
nix build .#lnbits
mkdir data
2022-07-13 01:15:48 +02:00
2022-07-28 12:19:30 +02:00
```
2022-07-13 01:15:48 +02:00
#### Running the server
2022-07-28 12:19:30 +02:00
2022-07-13 01:15:48 +02:00
```sh
2022-07-28 12:19:30 +02:00
# .env variables are currently passed when running
LNBITS_DATA_FOLDER=data LNBITS_BACKEND_WALLET_CLASS=LNbitsWallet LNBITS_ENDPOINT=https://legend.lnbits.com LNBITS_KEY=7b1a78d6c78f48b09a202f2dcb2d22eb ./result/bin/lnbits --port 9000
2022-07-13 01:15:48 +02:00
```
2022-07-27 16:01:23 +02:00
## Option 3: venv
2022-07-15 09:18:07 +02:00
```sh
git clone https://github.com/lnbits/lnbits-legend.git
cd lnbits-legend/
# ensure you have virtualenv installed, on debian/ubuntu 'apt install python3-venv'
python3 -m venv venv
# If you have problems here, try `sudo apt install -y pkg-config libpq-dev`
./venv/bin/pip install -r requirements.txt
# create the data folder and the .env file
mkdir data & & cp .env.example .env
2022-07-28 15:26:43 +02:00
# build the static files
./venv/bin/python build.py
2022-07-15 09:18:07 +02:00
```
2022-07-31 11:22:29 +02:00
#### Running the server
```sh
./venv/bin/uvicorn lnbits.__main__:app --port 5000
```
If you want to host LNbits on the internet, run with the option `--host 0.0.0.0` .
2022-07-30 17:09:14 +02:00
## Option 4: Docker
```sh
git clone https://github.com/lnbits/lnbits-legend.git
cd lnbits-legend
docker build -t lnbits-legend .
cp .env.example .env
mkdir data
docker run --detach --publish 5000:5000 --name lnbits-legend --volume ${PWD}/.env:/app/.env --volume ${PWD}/data/:/app/data lnbits-legend
```
2022-07-13 01:15:48 +02:00
### Troubleshooting
Problems installing? These commands have helped us install LNbits.
```sh
2022-07-23 10:39:58 +02:00
sudo apt install pkg-config libffi-dev libpq-dev
2022-07-13 01:15:48 +02:00
# if the secp256k1 build fails:
2022-07-28 12:43:31 +02:00
# if you used venv
2022-07-21 14:01:16 +02:00
./venv/bin/pip install setuptools wheel
2022-07-28 12:43:31 +02:00
# if you used poetry
poetry add setuptools wheel
2022-07-13 01:15:48 +02:00
# build essentials for debian/ubuntu
sudo apt install python3-dev gcc build-essential
```
### Optional: PostgreSQL database
If you want to use LNbits at scale, we recommend using PostgreSQL as the backend database. Install Postgres and setup a database for LNbits:
2022-01-27 21:07:47 +01:00
2021-11-12 12:38:07 +01: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 12:44:44 +01:00
sudo -i -u postgres
psql
2021-11-12 12:38:07 +01:00
# on psql
ALTER USER postgres PASSWORD 'myPassword'; # choose whatever password you want
\q
2021-11-12 12:44:44 +01:00
# on postgres user
createdb lnbits
2021-11-12 12:38:07 +01:00
exit
```
2020-09-03 19:53:22 +02:00
2022-07-13 01:15:48 +02:00
You need to edit the `.env` file.
2020-09-03 19:53:22 +02:00
```sh
2021-11-12 12:38:07 +01:00
# add the database connection string to .env 'nano .env' LNBITS_DATABASE_URL=
2022-01-14 10:20:20 +01:00
# postgres://<user>:<myPassword>@<host>/<lnbits> - alter line bellow with your user, password and db name
2021-11-12 12:38:07 +01:00
LNBITS_DATABASE_URL="postgres://postgres:postgres@localhost/lnbits"
# save and exit
2020-09-03 19:53:22 +02:00
```
2022-07-13 01:15:48 +02:00
# Using LNbits
2021-11-04 16:21:17 +01:00
Now you can visit your LNbits at http://localhost:5000/.
2020-09-03 19:53:22 +02:00
2022-07-13 01:15:48 +02: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.
2020-09-03 19:53:22 +02:00
2021-06-21 04:33:29 +02:00
Then you can restart it and it will be using the new settings.
2020-09-03 19:53:22 +02:00
2022-07-13 01:15:48 +02: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.
Take a look at [Polar ](https://lightningpolar.com/ ) for an excellent way of spinning up a Lightning Network dev environment.
2021-03-19 12:27:41 +01:00
2021-11-18 12:33:26 +01:00
2022-07-13 01:15:48 +02:00
# Additional guides
2022-07-21 14:01:16 +02:00
## SQLite to PostgreSQL migration
2022-07-13 01:15:48 +02:00
If you already have LNbits installed and running, on an SQLite database, we **highly** recommend you migrate to postgres if you are planning to run LNbits on scale.
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 (see Postgres install guide above). Additionally, your LNbits instance should run once on postgres to implement the database schema before the migration works:
2022-01-27 21:07:47 +01:00
2021-11-18 12:33:26 +01: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
2022-06-02 08:51:02 +02:00
# START LNbits
# STOP LNbits
2022-07-17 13:11:13 +02:00
# on the LNBits folder, locate and edit 'tools/conv.py' with the relevant credentials
python3 tools/conv.py
2021-11-18 12:33:26 +01:00
```
Hopefully, everything works and get migrated... Launch LNbits again and check if everything is working properly.
2022-07-21 14:01:16 +02:00
## LNbits as a systemd service
2022-01-27 21:07:47 +01:00
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 13:25:37 +02: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 21:07:47 +01:00
[Service]
2022-06-01 13:25:37 +02: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 21:07:47 +01:00
Restart=always
TimeoutSec=120
RestartSec=30
2022-06-01 13:25:37 +02:00
# this makes sure that you receive logs in real time
Environment=PYTHONUNBUFFERED=1
2022-01-27 21:07:47 +01: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
```
2022-07-21 14:01:16 +02:00
## Using https without reverse proxy
The most common way of using LNbits via https is to use a reverse proxy such as Caddy, nginx, or ngriok. However, you can also run LNbits via https without additional software. This is useful for development purposes or if you want to use LNbits in your local network.
We have to create a self-signed certificate using `mkcert` . Note that this certiciate is not "trusted" by most browsers but that's fine (since you know that you have created it) and encryption is always better than clear text.
#### Install mkcert
You can find the install instructions for `mkcert` [here ](https://github.com/FiloSottile/mkcert ).
Install mkcert on Ubuntu:
```sh
sudo apt install libnss3-tools
curl -JLO "https://dl.filippo.io/mkcert/latest?for=linux/amd64"
chmod +x mkcert-v*-linux-amd64
sudo cp mkcert-v*-linux-amd64 /usr/local/bin/mkcert
```
#### Create certificate
To create a certificate, first `cd` into your lnbits folder and execute the following command ([more info](https://kifarunix.com/how-to-create-self-signed-ssl-certificate-with-mkcert-on-ubuntu-18-04/))
```sh
# add your local IP (192.x.x.x) as well if you want to use it in your local network
mkcert localhost 127.0.0.1 ::1
```
This will create two new files (`localhost-key.pem` and `localhost.pem ` ) which you can then pass to uvicorn when you start LNbits:
```sh
./venv/bin/uvicorn lnbits.__main__:app --host 0.0.0.0 --port 5000 --ssl-keyfile ./localhost-key.pem --ssl-certfile ./localhost.pem
```
## LNbits running on Umbrel behind Tor
2021-07-07 11:58:21 +02:00
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.
2022-07-21 14:01:16 +02:00
## Docker installation
2021-03-19 12:27:41 +01:00
To install using docker you first need to build the docker image as:
2021-07-07 11:58:21 +02:00
2021-03-19 12:27:41 +01:00
```
git clone https://github.com/lnbits/lnbits.git
2021-06-21 04:33:29 +02:00
cd lnbits/ # ${PWD} referred as < lnbits_repo >
2021-03-19 12:27:41 +01:00
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 11:58:21 +02:00
2021-03-19 12:27:41 +01:00
```
cp < lnbits_repo > /.env.example .env
```
2021-07-07 11:58:21 +02:00
2021-03-19 12:27:41 +01: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 11:58:21 +02:00
2021-03-19 12:27:41 +01:00
```
mkdir data
sudo chown 1000:1000 ./data/
```
Then the image can be run as:
2021-07-07 11:58:21 +02:00
2021-03-19 12:27:41 +01:00
```
docker run --detach --publish 5000:5000 --name lnbits --volume ${PWD}/.env:/app/.env --volume ${PWD}/data/:/app/data lnbits
2021-06-19 03:41:30 +02:00
```
2021-07-07 11:58:21 +02:00
2021-06-21 04:33:29 +02:00
Finally you can access your lnbits on your machine at port 5000.