README.md
Introduction
This repository will help you install BTCPayServer, its environment, and all its dependencies.
As you can see, BTCPay depends on several pieces of infrastructure, mainly:
- A lightweight block explorer (NBXplorer),
- A database (PostgreSQL or SQLite),
- A full node (eg. Bitcoin Core)
There can be more dependencies if you support more than just standard Bitcoin transactions, including:
- C-Lightning
- LitecoinD and other coin daemons
- And more...
Note: The setup process can be time consuming, but is heavily automated to make it a fun and easy experience.
How do I use this?
One-click deployment
If you have no knowledge of Linux administration or Docker, we advise you to host BTCPay on Microsoft Azure:
First, open an Azure account, then:
Follow this video for the remaining steps:
This installation is convenient, but will cost you around 60 USD per month (unpruned). After all your nodes are synched and you confirm everything works, you can fine-tune (to save additional money) by following this guide; this will drop costs to 30 or 40 USD per month.
For technical users
You can also install BTCPayServer on your own machine or VPS instance.
First, make sure you have a domain name pointing to your host, with ports 443
and 80
externally accessible.
Let's assume it is btcpay.example.com
.
If you want to support Litecoin, Bitcoin, and C-Lightning, and want HTTPS automatically configured by Nginx:
# Login as root
sudo su -
# Create a folder for BTCPay
mkdir BTCPayServer
cd BTCPayServer
# Clone this repository
git clone https://github.com/btcpayserver/btcpayserver-docker
cd btcpayserver-docker
# Run btcpay-setup.sh with the right parameters
export BTCPAY_HOST="btcpay.example.com"
export NBITCOIN_NETWORK="mainnet"
export BTCPAYGEN_CRYPTO1="btc"
export BTCPAYGEN_CRYPTO2="ltc"
export BTCPAYGEN_REVERSEPROXY="nginx"
export BTCPAYGEN_LIGHTNING="clightning"
. ./btcpay-setup.sh -i
exit
btcpay-setup.sh
will:
- Install Docker
- Install Docker-Compose
- Make sure BTCPay starts at reboot via upstart or systemd
- Setup environment variables to use BTCPay utilities
- Add BTCPay utilities in /usr/bin
- Start BTCPay
Environment variables
btcpay-setup.sh
will use the following environment variables:
BTCPAY_HOST
: The hostname of your website (eg.btcpay.example.com
)NBITCOIN_NETWORK
: The type of network to use (eg.mainnet
,testnet
, orregtest
. Default:mainnet
)LIGHTNING_ALIAS
: An alias for your lightning network node, if usedBTCPAYGEN_CRYPTO1
: First supported crypto currency (eg.btc
,ltc
. Default:btc
)BTCPAYGEN_CRYPTO2
: Second supported crypto currency (eg.btc
,ltc
. Default:(empty)
)BTCPAYGEN_CRYPTON
: N'th supported crypto currency where N is 9 at maximum. (eg.btc
,ltc
. Default:(empty)
)BTCPAYGEN_REVERSEPROXY
: Whether to use or not a reverse proxy. NGinx setup HTTPS for you. (eg.nginx
,(empty)
. Default:nginx
)BTCPAYGEN_LIGHTNING
: Lightning network implementation to use (eg.clightning
,(empty)
)BTCPAYGEN_ADDITIONAL_FRAGMENTS
: Semicolon-separated list of additional fragments you want to use (eg.opt-save-storage
)LETSENCRYPT_EMAIL
: An email will be sent to this address if certificate expires and fail to renew automatically (eg.me@example.com
)ACME_CA_URI
: The API endpoint to ask for HTTPS certificate (Default:https://acme-v01.api.letsencrypt.org/directory
)BTCPAY_HOST_SSHKEYFILE
: Optional, SSH private key that BTCPay can use to connect to this VM's SSH server. This key will be copied to BTCPay's data directoryBTCPAY_SSHTRUSTEDFINGERPRINTS
: Optional, BTCPay will ensure that it is connecting to the expected SSH server by checking the host's public key against these fingerprints
Tooling
A wide variety of scripts are available once BTCPay is installed:
bitcoin-cli.sh
: Access your bitcoin node instancebitcoin-lightning-cli.sh
: Access your clightning node instancechangedomain.sh
: Change the domain of your BTCPayServerbtcpay-update.sh
: Update BTCPay to the latest versionbtcpay-up.sh
: Rundocker-compose up
btcpay-down.sh
: Rundocker-compose down
btcpay-setup.sh
: Change the settings of your server. ./btcpay-setup.sh
: Information about additional parameters. ./btcpay-setup.sh -i
: Setup your BTCPayServer
Under the hood
Generated docker-compose
Under the hood, your environment variables are used by build.sh (or build.ps1) to generate a docker-compose adapted for your needs.
By default, it will generate Generated/docker-compose.generated.yml
by gluing together the relevant Docker fragments for your setup.
To configure your custom docker-compose, the following environment variables are supported:
BTCPAYGEN_CRYPTO1
toBTCPAYGEN_CRYPTO9
: Specify support for a crypto currency. (eg.btc
,ltc
)BTCPAYGEN_REVERSEPROXY
: Specify the reverse proxy to use (eg.nginx
,none
)BTCPAYGEN_LIGHTNING
: Specify the lightning network implementation (eg.clightning
,none
)BTCPAYGEN_SUBNAME
: The sub name of the generated docker-compose file, where the full name will beGenerated/docker-compose.SUBNAME.yml
(Default:generated
)BTCPAYGEN_ADDITIONAL_FRAGMENTS
: Semicolon-separated list of additional fragments you want to use, (eg.opt-save-storage
, Default:(empty)
)
Available BTCPAYGEN_ADDITIONAL_FRAGMENTS
currently are:
- opt-save-storage will keep around 1 year of blocks (prune BTC for 100 GB)
- opt-save-storage-s will keep around 6 months of blocks (prune BTC for 50 GB)
- opt-save-storage-xxs will keep around 2 weeks of blocks (prune BTC for 5 GB) (lightning not supported)
You can also create your own custom fragments.
For example, if you want btc
and ltc
support with nginx
and clightning
inside Generated/docker-compose.custom.yml
:
Note: The first run might take a while, but following runs are instantaneous.
On Windows:
Invoke-Command {
$BTCPAYGEN_CRYPTO1="btc"
$BTCPAYGEN_CRYPTO2="ltc"
$BTCPAYGEN_REVERSEPROXY="nginx"
$BTCPAYGEN_LIGHTNING="clightning"
$BTCPAYGEN_SUBNAME="custom"
. .\build.ps1
}
On Linux:
BTCPAYGEN_CRYPTO1="btc" \
BTCPAYGEN_CRYPTO2="ltc" \
BTCPAYGEN_REVERSEPROXY="nginx" \
BTCPAYGEN_LIGHTNING="clightning" \
BTCPAYGEN_SUBNAME="custom" \
./build.sh
Next, you will need to configure the runtime environment variables for Generated/docker-compose.custom.yml
:
- If you are using NGinx, read this.
- If you are not using NGinx, read this instead.
What does btcpay-setup.sh
do?
btcpay-setup.sh
is a utility which does the following:
- Makes sure docker and docker-compose are installed on your system
- Generates a docker-compose via
./build.sh
- Sets up an Environment File to configure your docker-compose
- Sets up environment variables so the tools described in Tooling can work
- Adds symbolic links of those tools in
/usr/bin
- Starts docker-compose
- Makes sure it restarts at reboot via upstart or systemd
Here is an overview of the files generated by btcpay-setup.sh
:
/etc/profile.d/btcpay-env.sh
ensures that your environment variables are correctly setup when you login, so you can use the tools:
export BTCPAYGEN_OLD_PREGEN="false"
export BTCPAYGEN_CRYPTO1="btc"
export BTCPAYGEN_CRYPTO2=""
export BTCPAYGEN_CRYPTO3=""
export BTCPAYGEN_CRYPTO4=""
export BTCPAYGEN_CRYPTO5=""
export BTCPAYGEN_CRYPTO6=""
export BTCPAYGEN_CRYPTO7=""
export BTCPAYGEN_CRYPTO8=""
export BTCPAYGEN_CRYPTO9=""
export BTCPAYGEN_LIGHTNING="clightning"
export BTCPAYGEN_REVERSEPROXY="nginx"
export BTCPAYGEN_ADDITIONAL_FRAGMENTS=""
export BTCPAY_DOCKER_COMPOSE="/var/lib/waagent/custom-script/download/0/btcpayserver-docker/Production/docker-compose.generated.yml"
export BTCPAY_BASE_DIRECTORY="/var/lib/waagent/custom-script/download/0"
export BTCPAY_ENV_FILE="/var/lib/waagent/custom-script/download/0/.env"
export BTCPAY_HOST_SSHKEYFILE="/root/.ssh/id_rsa_btcpay"
if cat $BTCPAY_ENV_FILE &> /dev/null; then
export BTCPAY_HOST="$(cat $BTCPAY_ENV_FILE | sed -n 's/^BTCPAY_HOST=\(.*\)$/\1/p')"
export LETSENCRYPT_EMAIL="$(cat $BTCPAY_ENV_FILE | sed -n 's/^LETSENCRYPT_EMAIL=\(.*\)$/\1/p')"
export NBITCOIN_NETWORK="$(cat $BTCPAY_ENV_FILE | sed -n 's/^NBITCOIN_NETWORK=\(.*\)$/\1/p')"
export LIGHTNING_ALIAS="$(cat $BTCPAY_ENV_FILE | sed -n 's/^LIGHTNING_ALIAS=\(.*\)$/\1/p')"
export ACME_CA_URI="$(cat $BTCPAY_ENV_FILE | sed -n 's/^ACME_CA_URI=\(.*\)$/\1/p')"
export BTCPAY_SSHKEYFILE="$(cat $BTCPAY_ENV_FILE | sed -n 's/^BTCPAY_SSHKEYFILE=\(.*\)$/\1/p')"
export BTCPAY_SSHTRUSTEDFINGERPRINTS="$(cat $BTCPAY_ENV_FILE | sed -n 's/^BTCPAY_SSHTRUSTEDFINGERPRINTS=\(.*\)$/\1/p')"
fi
/etc/systemd/system/btcpayserver.service
ensures that you can control btcpay via systemctl
, and that BTCPayServer starts on reboot:
[Unit]
Description=BTCPayServer service
After=docker.service network-online.target
Requires=docker.service network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/bash -c '. /etc/profile.d/btcpay-env.sh && cd "$(dirname $BTCPAY_ENV_FILE)" && docker-compose -f "$BTCPAY_DOCKER_COMPOSE" up -d'
ExecStop=/bin/bash -c '. /etc/profile.d/btcpay-env.sh && cd "$(dirname $BTCPAY_ENV_FILE)" && docker-compose -f "$BTCPAY_DOCKER_COMPOSE" stop'
ExecReload=/bin/bash -c '. /etc/profile.d/btcpay-env.sh && cd "$(dirname $BTCPAY_ENV_FILE)" && docker-compose -f "$BTCPAY_DOCKER_COMPOSE" restart'
[Install]
WantedBy=multi-user.target
.env
($BTCPAY_ENV_FILE
) contains environment variables passed to the containers managed by your docker-compose:
BTCPAY_HOST=btcpay.example.com
ACME_CA_URI=https://acme-v01.api.letsencrypt.org/directory
NBITCOIN_NETWORK=mainnet
LETSENCRYPT_EMAIL=me@example.com
BTCPAY_SSHTRUSTEDFINGERPRINTS=SHA256:eSCD7NtQ/Q6IBl2iRB9caAQ3lDZd8s8iUL6SdeNnhpA
BTCPAY_SSHKEYFILE=/datadir/id_rsa
How can I add an altcoin to BTCPayServer?
- Add support for your crypto to NBitcoin, NBxplorer, and BTCPayServer. (Use examples from other coins)
- Create your own docker image (Example for BTC)
- Create a docker-compose fragment (Example for BTC)
- Add your CryptoDefinition (Example for BTC)
Now if you want to test, DO NOT USE build.sh
, because this utility is a pre-built docker image.
Instead, install .NET Core 2.1 SDK then run:
BTCPAYGEN_CRYPTO1="xxx"
BTCPAYGEN_SUBNAME="test"
cd docker-compose-generator/src
dotnet run
This will generate your docker-compose in the Generated
folder, which you can then try for yourself.
Note that BTCPayServer developers will not spend time testing your image, so make sure it works.
FAQ
How can I modify my environment?
As root, run . btcpay-setup.sh
; this will show you the environment variable it is expecting.
For example, if you support btc
and ltc
already, and want to add btg
:
export BTCPAYGEN_CRYPTO3='btg'
. btcpay-setup.sh -i
I deployed before btcpay-setup.sh
existed (before May 17), can I migrate to this new system?
Yes, run the following command to update:
sudo su -
btcpay-update.sh
cd $DOWNLOAD_ROOT/btcpayserver-docker
. ./btcpay-setup.sh -i
exit
I'm getting an error on Windows: Cannot create container for service docker: Mount denied
?
If you see this error:
Cannot create container for service docker: b'Mount denied:\nThe source path "\\\\var\\\\run\\\\docker.sock:/var/run/docker.sock"\nis not a valid Windows path'
.
Run this in powershell:
$Env:COMPOSE_CONVERT_WINDOWS_PATHS=1
Then, run docker-compose -f <your.yml> up
.
This bug comes from Docker for Windows and is tracked on Github.
How I can prune my node(s)?
This will prune your Bitcoin full node to a maximum of 100GB (of blocks):
export BTCPAYGEN_ADDITIONAL_FRAGMENTS="opt-save-storage"
. ./btcpay-setup.sh -i
Other options are opt-save-storage-s
(50 GB), opt-save-storage-xxs
(5 GB), or custom (see below).
How can I customize the generated docker-compose file?
In some instances, you might want to customize your environment in more detail. While you could modify Generated/docker-compose.generated.yml
manually, your changes would be overwritten the next time you run btcpay-update.sh
.
Luckily, you can leverage BTCPAYGEN_ADDITIONAL_FRAGMENTS
for this!
Let's enable pruning to 60 GB, for example:
First, copy opt-save-storage into the the docker fragment folder as opt-save-storage.custom.yml
. Important: the file must end with .custom.yml
, or there will be git conflicts whenever you run btcpay-update.sh
.
Modify the new opt-save-storage.custom.yml
file to your taste:
@@ -14,8 +14,7 @@ version: "3"
services:
bitcoind:
environment:
- BITCOIN_EXTRA_ARGS: prune=100000
+ BITCOIN_EXTRA_ARGS: prune=60000
Then set it up:
export BTCPAYGEN_ADDITIONAL_FRAGMENTS="opt-save-storage.custom"
. ./btcpay-setup.sh -i