Install your own instance of BTCPay Server on Ubuntu Server – Upgrade your Bitcoin Node

If you prefer video and don’t need help to install your own BTCPay Server instance on Ubuntu server, see this video for instructions. Use the below text as a way to help when you run in to something you don’t understand.

Install BTCPay Server

wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb

  • Install more software with:

sudo dpkg -i packages-microsoft-prod.deb

  • Remove a file that you no longer need:

rm packages-microsoft-prod.deb

  • Check for software updates:

sudo apt-get update

  • Install this package:

sudo apt-get install -y apt-transport-https

  • Check for updates to that package with:

sudo apt-get update

  • Install the .net package

sudo apt-get install -y dotnet-sdk-6.0

  • Next we install a database

sudo apt install postgresql postgresql-contrib

  • Change to user postgres with:

sudo -i -u postgres

  • Create a new user with:

createuser –pwprompt –interactive

  • You will be prompted to enter a username for this. Use whatever you’d like and make sure to take note of it.
  • You will be prompted to enter a password. It should be a secure password that you will remember.
  • You will be asked if this should be a ‘superuser’ – say no.
  • You will be asked if this user should be able to create a database – say yes.
  • You will be asked if this user should be able to create new roles – say no.
  • Create two databases, one for BTCPay Server and one for NBXplorer

createdb -O <the username you picked above> btcpayserver

createdb -O <the username you picked above> nbxplorer

  • Type command [exit] to get out of that username. You should be back in your downloads folder.
  • cd into your home directory with [cd ~]
  • Clone NBXplorer with the command:

git clone https://github.com/dgarage/NBXplorer

  • cd into NBXplorer with:

cd NBXplorer

  • Build NBXplorer with:

./build.sh

  • Create data directory in your home folder

mkdir -p ~/.nbxplorer/Main

  • cd into that using

cd ~/.nbxplorer/Main

  • Create a settings file

nano settings.config

  • Past this into the file:
btc.rpc.auth=<bitcoind rpc user>:<bitcoind rpc password>
port=24445
mainnet=1
postgres=User ID=<your db user>;Password=<your db password>;Host=localhost;Port=5432;Database=nbxplorer;
  • Change the bitcoin user to your bitcoind username, same with password. Also fix the postgres username and password you setup above. Control x, y, enter to save and exit
  • Back to the NBXplorer directory using: [cd ~]
  • Then cd into nbxplorer directory using [cd NBXplorer]
  • Run it using

./run.sh

  • You should see NBXplorer syncing up
  • Hit ‘control c’ to close it
  • Now we make a file to auto-start NBXplorer whenever the machine boots
  • cd into [cd /etc/systemd/system]
  • Paste this command into terminal:

sudo wget https://gist.githubusercontent.com/mariodian/de873b969e70eca4d0a7673efd697d0a/raw/acfc70c5694cd53d8a3df7ff54a35ff2caba7532/nbxplorer.service

  • Edit that file with command

Sudo nano nbxplorer.service

  • Edit the line that starts with ExecStart and find that part that says “netcoreapp2” to “net6.0”. Also remove the word /source from the filepath. Ensure username is accurate. Freedomnode uses ‘satoshi’ as the username, you may have changed that.
  • An example of that line: ExecStart=/usr/bin/dotnet “/home/<username>/NBXplorer/NBXplorer/bin/Release/net6.0/NBXplorer.dll” -c /home/<username>/.nbxplorer/Main/settings.config
  • Control x, y, enter to save and leave
  • Enable this using:

sudo systemctl enable nbxplorer.service

  • Start it:

sudo systemctl start nbxplorer.service

  • Check status:

sudo systemctl status nbxplorer.service

  • You should see a green dot showing NBXplore is up and running
  • Now we install BTCPay Server
  • Open a new terminal window and login to your node
  • In your home directory install BTCPay server

git clone https://github.com/btcpayserver/btcpayserver.git

  • cd into btcpayserver using:

cd btcpayserver

  • Build it with:

./build.sh

  • Make another directory:

mkdir -p ~/.btcpayserver/Main

  • cd into it:

cd ~/.btcpayserver/Main

  • Create a config file:

nano settings.config

  • Add these lines to it and change your username and pass to match what you entered for the postgres install:
network=mainnet
port=23001
bind=0.0.0.0
chains=btc
BTC.explorer.url=http://127.0.0.1:24445
#BTC.lightning=type=lnd-rest;server=https://127.0.0.1:8080/;macaroonfilepath=~/.lnd/data/chain/bitcoin/mainnet/admin.macaroon;certthumbprint=<finger print>
postgres=User ID=<yourusername>;Password=<your db password>;Host=localhost;Port=5432;Database=btcpayserver;
  • Go to home directory using

Cd ~

  • cd into btcpay server folder using

cd btcpayserver

  • Run it

./run.sh

  • Use a web browser to visit your ip address with :23001 at the end to see btcpay server running
  • Now we edit a service file

cd /etc/systemd/system

  • Now we download BTCPay service file:

sudo wget https://gist.githubusercontent.com/mariodian/07bb13da314e2a321784b380f543651a/raw/6cef554d9e8311e683a017d5e63a07822dee7642/btcpayserver.service

  • Edit the file using

Sudo nano btcpayserver.service

  • Fix the file path to remove the /source part
  • Fix the username in the file path also
  • Fix the user to match what you made
  • Fix the group to match you username
  • Enable the service:

sudo systemctl enable btcpayserver.service

  • Start it
sudo systemctl start btcpayserver.service
  • Check status:
sudo systemctl status btcpayserver.service