Ubuntu 16.04 LTS Setup Guide


#1

How to setup PhantomBot on Ubuntu Linux 16.04:

IMPORTANT!
You need a user which has root privileges on the server to get this working!
If you dont have root privileges, you may encounter unsolvable problems during setup.
But it is possible to get the bot running without them.

Note that this guide assumes that you are creating the botuser account for PhantomBot in the botuser group. If you change the username, be sure to take that into consideration when executing commands and configuring the service file for the OS.

1. Get Your System Ready:

First thing is to make sure, that your system is up to date. Before we install anything, we check if this is the case.

Type into the terminal or your SSH client:

sudo apt-get update
sudo apt-get upgrade

2. Setting up Java JDK:

PhantomBot requires Java to run on your machine. In this case, we will use the OpenJDK runtime which can be installed via apt-get.

To install the OpenJDK-Runtime we need to type the following into our terminal:

sudo apt-get install openjdk-8-jdk-headless

This will install all the necessary files we need to get PhantomBot running.

Now you can check your Java version with this command:

java -version

The output should be similar to this:

openjdk version "8-internal"
OpenJDK Runtime Environment (build 8-internal+0-2016-04-14-195246.buildd.src)
OpenJDK 64-Bit Server VM (build 8-internal+0-2016-04-14-195246.buildd.src, mixed mode)

Now we have Java installed and can get further to install PhantomBot.

3. Create a PhantomBot User:

IMPORTANT!
NEVER run this type of applications as root or root-user! Provide only necessary privileges to keep your server secure!

To create a new user and the corresponding home directory you have to type the following:

sudo addgroup botuser

sudo adduser botuser --ingroup botuser

Please take a good password! Nothing like 123 or similar are really secure!
Now we have created the user and the home directory for him.

4. Installing PhantomBot

Now we’re ready to install PhantomBot into our botuser directory.
First switch to your botuser:

sudo su - botuser

Switch to the home directory:

cd /home/botuser

Now we need to download the latest PhantomBot release:

sudo apt-get install wget

wget https://github.com/PhantomBot/PhantomBot/releases/download/vX.X.X/PhantomBot-X.X.X.zip
NOTE! Replace the X with current release version like PhantomBot-2.3.5.zip!

After the download has finished, we have to unzip the files.

sudo apt-get install unzip
unzip PhantomBot-X.X.X.zip
NOTE! Replace the X with current release version like PhantomBot-2.3.5.zip!

To make future updates a bit easier, we have to rename the PhantomBot folder.

mv PhantomBot-X.X.X phantombot

The last thing we need to do is to assign the right privileges to make the launch.sh and launch-service.sh files executable.

cd phantombot

chmod u+x launch-service.sh launch.sh
sudo chown -R botuser:botuser *

Now we are ready to launch PhantomBot. You can run the bot with:

./launch.sh

Now PhantomBot should start and you can begin to use it. At this point you can enter the information it asks you for. As a reference, you can check the Windows guide for the bot account configuration.

Ctrl + C

5. Setting Up A systemd Unit

Create a new file called phantombot.service. I use nano, but you can also use vi to write files.
sudo nano /etc/systemd/system/phantombot.service

Paste this into the file:

[Unit]
Description=PhantomBot
After=network.target remote-fs.target nss-lookup.target

[Service]
User=botuser
Group=botuser
Restart=on-failure
RestartSec=30
ExecStart=/home/botuser/phantombot/launch-service.sh
KillSignal=SIGTERM

[Install]
WantedBy=multi-user.target

After this, we have to install the created file to run at boot as a service.

sudo systemctl daemon-reload
sudo systemctl enable phantombot

Now one last thing we need to do, is to make the commands work to start|stop|restart PhantomBot.
We have to open the sudoers file to grant our botuser the rights to run these commands.

sudo visudo

On the end of the file add this:

botuser ALL=NOPASSWD: /bin/systemctl start phantombot, /bin/systemctl stop phantombot, /bin/systemctl restart phantombot

If an error is thrown, attempt to use /usr/bin/systemctl rather than /bin/systemctl.

Now the user “botuser” should have the rights to run the specific commands to start|stop|restart PhantomBot.
Let’s try it!

Switch to our botuser:

sudo su - botuser

Then as “botuser” try:

sudo /bin/systemctl start phantombot
sudo /bin/systemctl stop phantombot
sudo /bin/systemctl restart phantombot
If you have set up all correct it will start|stop|restart PhantomBot.

After PhantomBot is started, you can find your Control Panel under “YOUR-SERVER-IP:25000/panel”.
Make sure you open the following ports on your server: 25000-25004

6. Opening the Panel Ports

Enable the firewall.

sudo ufw enable

Allow SSH connections.

sudo ufw allow 22

Open the panel ports.

sudo ufw allow 25000:25004/tcp

Extra - Backup Every 24 Hours

We can have automated backups of PhantomBot very simply just by setting up a cronjob. Just follow these instructions.

sudo apt-get install bzip2
su - botuser
cd /home/botuser
mkdir -p backup/phantombot
crontab -e

Once the crontab is open, add:

1 4 * * * umask 0007;/bin/tar --exclude=/home/botuser/phantombot/lib --exclude=/home/botuser/phantombot/web -cjf /home/botuser/backup/phantombot/$(/bin/date +\%Y-\%m-\%d-\%H_\%M_\%S_\%3N).tar.bz2 /home/botuser/phantombot/ >>/home/botuser/backup/backup_phantombot.log 2>&1

Use this to check your crontab afterwards:

crontab -l

That’s it! Now once every 24 hours, PhantomBot will create a backup of itself in /home/botuser/backup/phantombot/.


Hosting bot on servers
Raspberry Pi 3, Ubuntu Mate and PhantomBot
Multiple bot instances on one vps (linux)
Updating from PB 2.3.6.1 to 2.3.7.1 on Raspberry Pi 3
Raspberry Pi 3, Ubuntu Mate and PhantomBot
Raspberry Pi 3, Ubuntu Mate and PhantomBot
VPS Installation
Make bot restart automatically every night
Auto Delete Back After X Days (using auto backup script)
Run phantombot on Ubuntu 14.04
`start phantombot` command won't work
Front-end for your viewers to check points | PHP Script
Transfer db from old to new updated version?