# Linux installation (and VPS)

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.

{% hint style="info" %}
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.
{% endhint %}

### 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**\
   ![](https://4092606354-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHeP19pbKbeSUZaxTjO7p%2Fuploads%2FmJ3PSZaTKx0eDPbDAbFf%2Fobrazek.png?alt=media\&token=93f6e0f3-29f6-4003-ab07-5b6965d2d790)
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.\
   ![](https://4092606354-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHeP19pbKbeSUZaxTjO7p%2Fuploads%2FBueUqKzbwPvOzCrsG5Tz%2Fobrazek.png?alt=media\&token=635c3bd8-2723-41cc-8e36-eaca7994db6a)
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&#x20;

   ```
   sudo apt install mariadb-server
   ```
2. Start and enable it&#x20;

   ```
   sudo systemctl enable --now mariadb
   ```
3. Go through the guided initial setup&#x20;

   ```
   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.&#x20;

   ```
   FLUSH PRIVILEGES;
   ```
5. To quit, type&#x20;

   ```
   EXIT 
   ```

#### phpMyAdmin setup

1. Download zipped phpMyAdminFiles

   <pre><code>wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz
   <strong>sudo tar xvf phpMyAdmin-latest-all-languages.tar.gz
   </strong>sudo mv phpMyAdmin-*-all-languages/ /var/www/html/phpmyadmin
   </code></pre>
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. \
    ![](https://4092606354-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHeP19pbKbeSUZaxTjO7p%2Fuploads%2FW0j3IDA1CrHHJDZISGtQ%2Fobrazek.png?alt=media\&token=b2e14b5a-1a49-4752-a7d1-280527dcf6b3)

#### 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**: \
   ![](https://4092606354-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHeP19pbKbeSUZaxTjO7p%2Fuploads%2FiBrntJAeMe1SdtfYh0yA%2Fobrazek.png?alt=media\&token=a895c87e-da57-4462-854f-62750b219faf)
3. Log in to your server and navigate to FoxCodeBot directory
4. Upload the unzipped bot files you downloaded to the folder\
   ![](https://4092606354-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHeP19pbKbeSUZaxTjO7p%2Fuploads%2Fn2iso6z5OUpNprHSos5z%2Fobrazek.png?alt=media\&token=fa31cf61-fc09-41a0-be83-749f6146e46e)
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`

{% hint style="success" %}
Done, you should be good to go! Now you can move on to Modules installation!
{% endhint %}

{% hint style="warning" %}
If you have any issues during the installation, feel free to join our Discord server and ask for help there! :relaxed::coffee:
{% endhint %}

### Summary - required packages

#### Python

```
discord.py
mysql-connector-python
pyyaml
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.foxcodebot.fox-code.eu/installation/linux-installation-and-vps.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
