Linux installation (and VPS)

This page will guide you through the process of hosting the bot on your Linux server.

Please, note that this procedure should work on Debian based Linux distros, other distros may use different commands to install certain things. I am going to use Hetzner VPS with their preinstalled version of Debian 11 for this guide.

You can use my referral link to get 20€ for registration, which can fund hosting of your bot for a few months: https://hetzner.cloud/?ref=4mXmogDkNdVc. Note, that I am also going to recieve a small reward for you using the referral, so it's a win-win. You don't have to, it's up to you which provider you choose, but I can recommend Hetzner for their prices, performance, wide range of server locations to select from and their server stability.

Setting up a Linux VPS with FoxCodeBot

Ordering and creating a VPS

  1. Log in into your account on Hetzner Cloud (https://console.hetzner.cloud)

  2. Create a project and click CREATE A SERVER

  3. Select a region that is closest to you, Debian 11 as an OS. Server type can be the cheapest one, all the packages have a lot more power than the bot needs.

  4. Give your server a name, than order the VPS by clicking CREATE & BUY NOW and wait a few minutes for the server to get ready

  5. Open your e-mail. In your mail inbox, you should have server SSH login details from Hetzner.

  6. Open your SSH client (you can also use command promt/terminal, if you are on Windows), connect to the server using: ssh root@your-ip-adress and use the password from the mail.

  7. Change your password, it should automatically promt you. If not, you can do so with passwd command

  8. Once you are there, update all packages using apt update & apt upgrade -y

Python 3 and its packages

  1. Next we are going to install Python 3 and all packages the bot depends on. Use this to install Python 3 and pip apt install python3 python3-pip -y

  2. Install python packages the bot depends on with pip3 install -U discord.py mysql-connector-python pyyaml

MySQL database and phpMyAdmin

MariaDB setup

  1. Install MariaDB package

    sudo apt install mariadb-server
  2. Start and enable it

    sudo systemctl enable --now mariadb
  3. Go through the guided initial setup

    sudo mysql_secure_installation

Create administrator database account

  1. Open MySQL console

    sudo mysql
  2. Create new admin user. The password is up to you.

    CREATE USER 'admin'@localhost IDENTIFIED BY 'password';
  3. Grant the account all permissions including ability to create more users.

    GRANT ALL ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;  
  4. Apply the changes.

    FLUSH PRIVILEGES;
  5. To quit, type

    EXIT 

phpMyAdmin setup

  1. Download zipped phpMyAdminFiles

    wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz
    sudo tar xvf phpMyAdmin-latest-all-languages.tar.gz
    sudo mv phpMyAdmin-*-all-languages/ /var/www/html/phpmyadmin
  2. Create a configuration file based on phpMyAdmin exapmle

    cd /var/www/html
    sudo cp phpmyadmin/config.sample.inc.php phpmyadmin/config.inc.php
  3. Create a temporary storage

    sudo mkdir /var/www/html/phpmyadmin/tmp
  4. Now open the configuration file

    sudo nano /var/www/html/phpmyadmin/config.inc.php
  5. Edit line with $cfg[‘blowfish_secret’] = ‘your-key‘; You should replace this with 32 character long secret phrase

  6. At the end of the config insert new line

    $cfg['TempDir'] = '/var/www/html/phpmyadmin/tmp';
  7. After all, this, Save the file by pressing Ctrl+O, hit the Enter key, and then Ctrl+X to exit.

  8. Change file permissions to allow webserver to access these files

    sudo chown -R www-data:www-data /var/www/html/phpmyadmin
  9. Create Apache config file

    sudo nano /etc/apache2/conf-available/phpmyadmin.conf
  10. Paste this configuration inside the file

    Alias /phpmyadmin /var/www/html/phpmyadmin
    
    <Directory /var/www/html/phpmyadmin/>
       AddDefaultCharset UTF-8
       <IfModule mod_authz_core.c>
              <RequireAny>
          Require all granted
         </RequireAny>
       </IfModule>
    </Directory>
    
    <Directory /var/www/html/phpmyadmin/setup/>
       <IfModule mod_authz_core.c>
         <RequireAny>
           Require all granted
         </RequireAny>
       </IfModule>
    </Directory>
  11. Save the file by pressing Ctrl+O, hit the Enter key, and then Ctrl+X to exit.

  12. Activate the configuration

    sudo a2enconf phpmyadmin.conf
  13. Restart the webserver

    sudo systemctl restart apache2
  14. Done! Access the web interface using http://your-server-ip/phpmyadmin

  15. Login using the database account we created earlier. You can now easily manage your databases, create and delete new ones.

Creating a bot folder, importing files

  1. Create a folder for our bot, to make things more organised mkdir /FoxCodeBot cd /FoxCodeBot

  2. To make things easier, connect to your server with files manager. You can do that with any FTP/SCP client, I am used to WinSCP:

  3. Log in to your server and navigate to FoxCodeBot directory

  4. Upload the unzipped bot files you downloaded to the folder

  5. Open the config.yml and insert your bot token and database credentials

Running the bot 24/7 using PM2

  1. Install pm2 using these commands: apt install npm -y npm i -g pm2

  2. Make sure you are in the bot folder

  3. Run following commands npm i pm2 -g npm i

  4. Run the bot using the command bellow, you can choose your own name pm2 start main.py --name FoxCodeBot --interpreter python3

  5. Check the log to make sure, that everything is running without errors pm2 logs FoxCodeBot

Summary - required packages

Python

discord.py
mysql-connector-python
pyyaml

Last updated

Was this helpful?