2018-11-12 00:26:00 +01:00
# Create Your Own Spee.ch on Ubuntu 16.x 18.x VPS
# Overview
## Prerequisites
* Ability to use SSH (putty + public key for windows users)
* Ubuntu 16.04 or 18.04 VPS with root access
2019-03-01 09:03:53 +01:00
* Your login info ready
2018-12-09 05:11:10 +01:00
* Exposed ports: 22, 80, 443, 3333, 4444
2018-11-12 00:26:00 +01:00
* Domain name with @ and www pointed at your VPS IP
2018-12-09 05:11:10 +01:00
* _alternatively, specify http://localhost:3000 as domain during speech configuration_
2018-11-12 00:26:00 +01:00
* Ability to send 5+ LBRY credits to an address
* Noncommercial use
2018-12-09 05:11:10 +01:00
* _alternative configuration examples for nginx and certbot are [here ](https://github.com/lbryio/spee.ch/tree/master/docs/setup/conf/nginx )_
2018-11-12 00:26:00 +01:00
## You'll be installing:
2018-12-09 05:11:10 +01:00
* MySQL DB version 5.7 or higher
2018-11-12 00:26:00 +01:00
* Default Port 3306
2018-12-09 05:11:10 +01:00
* mysql_native_password plugin
2018-11-12 00:26:00 +01:00
* NodeJS v8+
2018-12-09 05:11:10 +01:00
* Caddy - https reverse proxy server
* automatically obtains tls certificate
* Redirects 80 (http) to 443 (https) to Speech on 3000
2018-11-12 00:26:00 +01:00
* Lbrynet DAEMON started on ports 3333 and 4444
2018-12-09 05:11:10 +01:00
* Spee.ch started on port 3000
2018-11-12 00:26:00 +01:00
2018-11-12 19:53:29 +01:00
# 1. Setup OS and install dependencies
2018-11-12 00:26:00 +01:00
## OS
### Secure your server by creating a non-root sudoer.
As root# _create user and add to sudo group_
```
adduser username
usermod -aG sudo username
su - username
```
2018-11-19 02:13:04 +01:00
As username: *paste public key in authorized\_keys*
2018-11-12 00:26:00 +01:00
```
`cd`
`mkdir .ssh`
`nano ~/.ssh/authorized_keys`
```
### Prep
2019-03-01 08:23:57 +01:00
ssh to username@domainname or username@ip_address
2018-11-12 00:26:00 +01:00
2019-03-01 08:23:57 +01:00
```
sudo apt-get update -y
ulimit -n 8192
wget -qO- https://deb.nodesource.com/setup_8.x | sudo -E bash -
```
2018-11-12 00:26:00 +01:00
## Git, Curl, Tmux, Unzip, ffmpeg, Node
2019-03-01 09:07:01 +01:00
`sudo apt-get install git curl tmux unzip ffmpeg nodejs imagemagick -y`
2018-11-12 00:26:00 +01:00
## Clone speech either from your own fork, or from the lbryio/spee.ch repo.
2018-11-12 19:53:29 +01:00
* For Developers - our master branch
2018-11-12 00:26:00 +01:00
2018-11-12 19:53:29 +01:00
`git clone https://github.com/lbryio/spee.ch`
2018-11-12 00:26:00 +01:00
2018-11-12 19:53:29 +01:00
* For Developers - your fork
2018-11-12 00:26:00 +01:00
`git clone https://github.com/{{youraccount}}/spee.ch.git`
2018-11-12 19:53:29 +01:00
`git clone git@github.com:{{youraccount}}/spee.ch`
2018-11-12 00:26:00 +01:00
2018-11-12 19:53:29 +01:00
* For Publishers and Content creators - stable release
2018-11-12 00:26:00 +01:00
`git clone -b release https://github.com/lbryio/spee.ch`
2018-11-12 19:53:29 +01:00
## Prepare the scripts
2018-11-12 00:26:00 +01:00
`chmod 750 -R ~/spee.ch/docs/setup`
# 2 Secure the UFW firewall
## UFW
`sudo ~/spee.ch/docs/setup/scripts/firewall.sh`
# 3 Install Caddy to handle https and reverse proxy
## Get Caddy
`curl https://getcaddy.com | sudo bash -s personal`
## Set up Caddy reverse proxy and ssl
2019-03-01 08:23:57 +01:00
```
sudo mkdir -p /opt/caddy/logs/
sudo mkdir -p /opt/caddy/store/
cp ~/spee.ch/docs/setup/conf/caddy/Caddyfile.template ~/spee.ch/docs/setup/conf/caddy/Caddyfile
nano ~/spee.ch/docs/setup/conf/caddy/Caddyfile
```
2018-11-19 02:13:04 +01:00
2018-11-12 00:26:00 +01:00
( Change {{EXAMPLE.COM}} to YOURDOMAIN.COM )
`sudo cp ~/spee.ch/docs/setup/conf/caddy/Caddyfile /opt/caddy/`
## Set up Caddy to run as systemd service
2019-03-01 08:23:57 +01:00
```
sudo cp ~/spee.ch/docs/setup/conf/caddy/caddy.service /etc/systemd/system/caddy.service
sudo chmod 644 /etc/systemd/system/caddy.service
sudo chown -R www-data:www-data /opt/caddy/
sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/caddy
sudo systemctl daemon-reload
sudo systemctl start caddy
sudo systemctl status caddy
```
2018-11-12 00:26:00 +01:00
`q` exits
At this point, navigating to yourdomain.com should give you a 502 bad gateway error. That's good!
2018-11-19 02:13:04 +01:00
Now you can make sure caddy starts when the machine starts:
`sudo systemctl enable caddy`
2018-11-12 00:26:00 +01:00
# 4 Set up MySQL
## Install MySQL
`sudo apt-get install mysql-server -y`
2018-11-19 02:13:04 +01:00
2018-12-18 01:33:42 +01:00
( During install, enter blank password each time if prompted. We'll set one during secure setup.)
2018-11-12 00:26:00 +01:00
`sudo systemctl status mysql` (q to exit)
## Secure Setup
`sudo mysql_secure_installation`
2018-12-18 01:33:42 +01:00
2018-11-19 02:13:04 +01:00
* Password your_mysql_password
2018-11-12 00:26:00 +01:00
* No to password validation
* Y to all other options
## Login to mysql from root to complete setup:
`sudo mysql` to enter mysql> console
mysql>
2018-11-19 02:13:04 +01:00
`ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_mysql_password';`
2018-11-12 00:26:00 +01:00
mysql>
`FLUSH PRIVILEGES;`
`Control+D` to exit
Verify:
2018-11-19 02:13:04 +01:00
`mysql -u root -p` and then entering your_mysql_password should give you the mysql> shell
2018-11-12 00:26:00 +01:00
2019-02-22 00:12:42 +01:00
# 5 Get Lbrynet SDK Daemon
2018-11-12 00:26:00 +01:00
2019-03-01 08:23:57 +01:00
## Get the SDK
2018-11-12 00:26:00 +01:00
2019-03-01 08:23:57 +01:00
We'll be putting it in /opt/lbry.
`sudo mkdir /opt/lbry`
2019-03-01 09:03:53 +01:00
2019-03-01 08:23:57 +01:00
`sudo wget -O /opt/lbry/latest_daemon.zip https://lbry.io/get/lbrynet.linux.zip`
2019-03-01 09:03:53 +01:00
2019-03-01 08:23:57 +01:00
`sudo unzip -o -u /opt/lbry/latest_daemon.zip -d /opt/lbry`
2018-11-12 00:26:00 +01:00
2019-03-01 08:23:57 +01:00
## Set up lbrynet to run as systemd service
2018-11-12 00:26:00 +01:00
2019-03-01 08:23:57 +01:00
We'll soon update the setup scripts. Meanwhile, here's an example lbrynet.service file
```
[Unit]
Description="LBRYnet daemon"
After=network.target
# Change environment to /home/{{USERNAME}}
[Service]
Environment="HOME=/home/{{USERNAME}}"
ExecStart=/opt/lbry/lbrynet start
User={{USERNAME}}
Group={{USERNAME}}
Restart=on-failure
KillMode=process
[Install]
WantedBy=multi-user.target
```
2019-03-01 09:03:53 +01:00
`sudo nano /etc/systemd/system/lbrynet.service`
2019-03-01 08:23:57 +01:00
Then paste the above into the file and edit replacing {{USERNAME}} with yours.
Finally do the following.
```
sudo chmod 644 /etc/systemd/system/lbrynet.service
sudo systemctl daemon-reload
sudo systemctl start lbrynet
sudo systemctl status lbrynet
```
2018-11-12 00:26:00 +01:00
2019-03-01 08:23:57 +01:00
You'll find your lbrynet logs in ~/.local/share/lbry/lbrynet/lbrynet.log
Now let's make sure we're back in our home directory. `cd`
2018-11-12 00:26:00 +01:00
2019-02-22 00:12:42 +01:00
## Customize SDK settings
2019-02-22 04:38:00 +01:00
These settings will prevent you and your users from spending your server's LBC on paid content. Full documentation is [here ](https://lbry.tech/resources/daemon-settings ).
2019-02-22 00:12:42 +01:00
~$
`mkdir .lbrynet`
`cd .lbrynet`
`nano daemon_settings.yml`
copy and paste in the following code (Ctrl+Shift V)
```
run_reflector_server: false
max_key_fee: {amount: 0, currency: LBC}
use_upnp: false
auto_re_reflect_interval: 0
```
`CONTROL+O` then `CONTROL+X` to save and exit
2018-11-12 00:26:00 +01:00
2019-03-01 08:23:57 +01:00
## Display wallet address to which to send 5+ LBC.
2018-11-19 02:13:04 +01:00
2019-03-01 08:23:57 +01:00
_note: These commands work when `lbrynet` is already running_
2018-11-12 00:26:00 +01:00
2019-03-01 08:23:57 +01:00
Let's make our lives easier and link /opt/lbry/lbrynet in /usr/local/bin
2018-11-12 00:26:00 +01:00
2019-03-01 08:23:57 +01:00
`sudo ln -s /opt/lbry/lbrynet /usr/local/bin/lbrynet`
2018-11-12 00:26:00 +01:00
2019-03-01 08:23:57 +01:00
`lbrynet commands` to check out the current commands
2018-11-12 00:26:00 +01:00
2019-03-01 08:23:57 +01:00
`lbrynet address list` to get your wallet address
2018-11-12 00:26:00 +01:00
`Ctrl + Shift + C` after highlighting an address to copy.
Use a LBRY app or daemon to send LBC to the address. Sending LBC may take a few seconds or longer.
2019-03-01 08:23:57 +01:00
`lbrynet account balance` to check your balance after you've sent LBC.
2018-11-12 00:26:00 +01:00
# 6 Set up spee.ch
## Build it
2018-11-12 19:53:29 +01:00
`cd spee.ch`
~/spee.ch:
`npm install`
2018-11-12 00:26:00 +01:00
2018-11-12 19:53:29 +01:00
_note: if you have installed your own local chainquery instance, you will need to specify it in your own /site/config/chainqueryConfig.json_
2018-11-12 00:26:00 +01:00
2018-11-12 19:53:29 +01:00
Once your wallet has a balance, run this:
2018-11-12 00:26:00 +01:00
2018-12-18 01:33:42 +01:00
`npm run configure`
2018-12-09 05:11:10 +01:00
2018-12-18 01:33:42 +01:00
The script will ask for the following values:
2018-11-12 00:26:00 +01:00
* Database: lbry
* Username: root
2018-11-19 02:13:04 +01:00
* Password: your_mysql_password
2018-11-12 00:26:00 +01:00
* Port: 3000
* Site Title: Your Site Name
2018-12-09 05:11:10 +01:00
* Enter your site's domain name: https://example.com or http://localhost:3000
2018-11-12 00:26:00 +01:00
* Enter a directory where uploads should be stored: (/home/lbry/Uploads)
2018-12-18 01:33:42 +01:00
`npm run build` (or `npm run dev` to build for developing)
2018-11-12 00:26:00 +01:00
`npm run start`
## Try it
2018-11-12 19:53:29 +01:00
Navigate to example.com!
2018-11-12 00:26:00 +01:00
# 7 Production
## pm2 to keep your speech app running
```
npm install -g pm2
```
2018-12-09 05:11:10 +01:00
### 7 Maintenance Procedures
2018-11-12 00:26:00 +01:00
#### Change daemon
* backup wallet (private keys!) to a safe place
* wget daemon from https://github.com/lbryio/lbry/releases
* wget -O ~/your_name_daemon.zip https://your_copied_file_path.zip
* rm ./lbrynet
* unzip -o -u ~/your_name_daemon.zip